python - Django : migration success but not creating new table

标签 python mysql django

我一直在使用 django 迁移来处理数据库。最近,我把session分成两部分,一个是阅读,一个是写作。完成此操作后,我制作了添加新表并运行它的新迁移文件。成功了,

Operations to perform:
Apply all migrations: food
Running migrations:
Applying food.0107_auto_20171116_0849... OK

但是我用shell查看mysql数据库,并没有新表。我删除了 django 迁移历史并尝试了几次,但结果是一样的。它说已应用迁移,但没有新表。这是我的迁移文件

# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-11-16 08:49
from __future__ import unicode_literals

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

    dependencies = [
        ('bubi', '0106_auto_20171110_1452'),
    ]

    operations = [
        migrations.CreateModel(
           name='FoodHistory',
              fields=[
                  ('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
                  ('date', models.DateField(verbose_name='updated date')),
        ],
        options={
            'verbose_name': 'food updated date',
            'verbose_name_plural': 'food updated date',
        },
    ),
]

我想知道拆分 session 是否会影响迁移。谢谢!

编辑

我添加了我的 local_settings.py

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'food',
    'HOST': '127.0.0.1',
    'USER': 'apple',
    'PASSWORD': 'apple'
},
'read': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'food',
    'HOST': '127.0.0.1',
    'USER': 'apple',
    'PASSWORD': 'apple'
},
'write': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'food',
    'HOST': '127.0.0.1',
    'USER': 'apple',
    'PASSWORD': 'apple'
}
}

最佳答案

如果你在Django中使用了多个DB,迁移时,你需要检查你编码的Database Router。

检查数据库路由器类中的“allow_migrate”方法。

这是关于这个问题的官方 Django 文档。

https://docs.djangoproject.com/ko/1.11/topics/db/multi-db/#allow_migrate

关于python - Django : migration success but not creating new table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47319915/

相关文章:

python - 如何在同一行显示两个打印语句的输出?

mysql - 资源密集型 MySQL 嵌套选择

mysql在不满足JOIN条件时选择虚拟记录

python - 如何包装第 3 方 Django 应用程序的 View

python - Azure 上的 Django + FastCGI 应用程序,频繁重启

python - 将元组的 spark RDD 转换为 numpy 数组

python - 为组中的一个点格式化注释

C# - 如何将特定记录从数据库显示到 ASP.NET MVC 中的 View

python - Facebook 身份验证 : server-side versus client-side. Python/Django

django - 如何将 INFO 和 ERROR 日志隔离在其自己的文件路径中