0
每一個:我想練習使用Django 1.8,MySQL數據庫與傳統數據庫集成Django的,但它並沒有取得成功,任何一個可以告訴我發生了什麼?謝謝非常! 我遺留數據庫與傳統數據庫整合Django不工作
models.py
# -*- coding: utf-8 -*-
from django.db import models
from django.utils import timezone
class blog(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
slug = models.SlugField(unique=True)
date_time = models.DateTimeField(auto_now_add = True)
def __unicode__(self):
return self.name
def get_image_path(instance, filename):
return '/'.join(['blog_images', instance.bupimg.slug, filename])
class Upload(models.Model):
bupimg = models.ForeignKey(blog, related_name="uploads")
image = models.ImageField(upload_to=get_image_path)
,我只是按照doc here
爲什麼我pidapp /模型.py顯示非常不同的t韓原有數據庫的models.py
pidapp/models.py
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
#
# Also note: You'll have to insert the output of 'django-admin sqlcustom [app_label]'
# into your database.
from __future__ import unicode_literals
from django.db import models
class AuthGroup(models.Model):
name = models.CharField(unique=True, max_length=80)
class Meta:
managed = False
db_table = 'auth_group'
class AuthGroupPermissions(models.Model):
group = models.ForeignKey(AuthGroup)
permission = models.ForeignKey('AuthPermission')
class Meta:
managed = False
db_table = 'auth_group_permissions'
unique_together = (('group', 'permission'),)
class AuthPermission(models.Model):
name = models.CharField(max_length=255)
content_type = models.ForeignKey('DjangoContentType')
codename = models.CharField(max_length=100)
class Meta:
managed = False
db_table = 'auth_permission'
unique_together = (('content_type', 'codename'),)
class AuthUser(models.Model):
password = models.CharField(max_length=128)
last_login = models.DateTimeField(blank=True, null=True)
is_superuser = models.IntegerField()
username = models.CharField(unique=True, max_length=30)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.CharField(max_length=254)
is_staff = models.IntegerField()
is_active = models.IntegerField()
date_joined = models.DateTimeField()
class Meta:
managed = False
db_table = 'auth_user'
class AuthUserGroups(models.Model):
user = models.ForeignKey(AuthUser)
group = models.ForeignKey(AuthGroup)
class Meta:
managed = False
db_table = 'auth_user_groups'
unique_together = (('user', 'group'),)
class AuthUserUserPermissions(models.Model):
user = models.ForeignKey(AuthUser)
permission = models.ForeignKey(AuthPermission)
class Meta:
managed = False
db_table = 'auth_user_user_permissions'
unique_together = (('user', 'permission'),)
class BloggingBlog(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
slug = models.CharField(unique=True, max_length=50)
date_time = models.DateTimeField()
class Meta:
managed = False
db_table = 'blogging_blog'
class BloggingUpload(models.Model):
bupimg = models.ForeignKey(BloggingBlog)
image = models.CharField(max_length=100)
class Meta:
managed = False
db_table = 'blogging_upload'
class DjangoAdminLog(models.Model):
action_time = models.DateTimeField()
object_id = models.TextField(blank=True, null=True)
object_repr = models.CharField(max_length=200)
action_flag = models.SmallIntegerField()
change_message = models.TextField()
content_type = models.ForeignKey('DjangoContentType', blank=True, null=True)
user = models.ForeignKey(AuthUser)
class Meta:
managed = False
db_table = 'django_admin_log'
class DjangoContentType(models.Model):
app_label = models.CharField(max_length=100)
model = models.CharField(max_length=100)
class Meta:
managed = False
db_table = 'django_content_type'
unique_together = (('app_label', 'model'),)
class DjangoMigrations(models.Model):
app = models.CharField(max_length=255)
name = models.CharField(max_length=255)
applied = models.DateTimeField()
class Meta:
managed = False
db_table = 'django_migrations'
class DjangoSession(models.Model):
session_key = models.CharField(primary_key=True, max_length=40)
session_data = models.TextField()
expire_date = models.DateTimeField()
class Meta:
managed = False
db_table = 'django_session'
class RegistrationRegistrationprofile(models.Model):
activation_key = models.CharField(max_length=40)
user = models.ForeignKey(AuthUser, unique=True)
activated = models.IntegerField()
class Meta:
managed = False
db_table = 'registration_registrationprofile'
我認爲pidapp/models.py應該是一樣的傳統數據庫的models.py
右,,,其實我只是練習,如果我可以集成Django的使用遺留數據庫或不,,所以我創建了一個models.py並嘗試從另一個Django項目inspectdb它,,,不過,我需要知道我可以做到這一點 –
但你沒* *它,你的模型已經正確生成。你顯示的輸出有什麼問題? –
我認爲models.py應該是相同的代碼,,,但它並沒有,,,你在我的MySQL的意思,,他們的表已經集成? –