将Django与遗留数据库集成

时间:2016-05-11 02:36:58

标签: django

o遗留数据库表信息

MEM_ID  MEM_SQ  X_AUTH_USER X_AUTH_KEY  X_STORAGE_URL   ACCESSKEY

o我的应用信息模型  提到https://docs.djangoproject.com/en/dev/howto/legacy-databases/

python manage.py inspectdb

迁移db

python manage.py migrate

我的应用模型

 class SsAuthList(models.Model):
    mem_id = models.CharField(db_column='MEM_ID', max_length=62, blank=True, null=True)  # Field name made lowercase.
    mem_sq = models.CharField(db_column='MEM_SQ', max_length=50, blank=True, null=True)  # Field name made lowercase.
    x_auth_user = models.CharField(db_column='X_AUTH_USER', max_length=59, blank=True, null=True)  # Field name made lowercase.
    x_auth_key = models.CharField(db_column='X_AUTH_KEY', max_length=50, blank=True, null=True)  # Field name made lowercase.
    x_storage_url = models.CharField(db_column='X_STORAGE_URL', max_length=71, blank=True, null=True)  # Field name made lowercase.
    accesskey = models.CharField(db_column='ACCESSKEY', max_length=62, blank=True, null=True)  # Field name made lowercase.

已检查管理员网站。但不是db表的信息 (遗留数据库行为500) enter image description here

1 个答案:

答案 0 :(得分:0)

也许问题是你丢失了元类定义:

class SsAuthList(models.Model):
    mem_id = models.CharField(db_column='MEM_ID', max_length=62, blank=True, null=True)
    mem_sq = models.CharField(db_column='MEM_SQ', max_length=50, blank=True, null=True)
    x_auth_user = models.CharField(db_column='X_AUTH_USER', max_length=59, blank=True, null=True)
    x_auth_key = models.CharField(db_column='X_AUTH_KEY', max_length=50, blank=True, null=True)
    x_storage_url = models.CharField(db_column='X_STORAGE_URL', max_length=71, blank=True, null=True)
    accesskey = models.CharField(db_column='ACCESSKEY', max_length=62, blank=True, null=True)

    class Meta:
       managed = False
       db_table = 'TABLE_NAME'