Django 执行 makemigrations 显示 No changes detected in app

在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。 

 

posted @ 2019-09-10 11:52  北斗星君  阅读(4421)  评论(1编辑  收藏  举报