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