当前位置: 移动技术网 > IT编程>脚本编程>Python > Django 执行 makemigrations 显示 No changes detected in app

Django 执行 makemigrations 显示 No changes detected in app

2019年09月10日  | 移动技术网IT编程  | 我要评论

造梦西游3混元龙铠,野针王,北京缓解拥堵网摇号结果查询

在django项目配置一下多数据库,但是运行 makemigrations 执行不正常

$ python manage.py makemigrations polls
no changes detected in app 'polls'

 

models.py 代码:

class question(models.model):
    question_text = models.charfield(max_length=200)
    pub_date = models.datetimefield('date published')

    class meta:
        app_label = 'apps.polls'

 

删除 class meta,执行成功了。

$ python manage.py makemigrations polls
migrations for 'polls':
  apps\polls\migrations\0001_initial.py
    - create model question

然后执行 python manage.py migrate polls --database=app_db_name,数据库只产生了django_migrations, 没有生成对应的表

调整setting.py

database_apps_mapping = {
    # 'apps.polls': 'db_name',
    'polls': 'db_name',
}
class question(models.model):
    question_text = models.charfield(max_length=200)
    pub_date = models.datetimefield('date published')

    class meta:
        app_label = 'polls'

 重新执行 makemigrations 和 migrate, 数据库存成功生成数据表  polls_question。 

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网