简体   繁体   English

Django:迁移成功但没有创建新表

[英]Django : migration success but not creating new table

I've been using django migration to handle database. 我一直在使用django迁移来处理数据库。 recently, I split session into two, one is for reading and the other one is for writing. 最近,我将会话分为两部分,一部分用于阅读,另一部分用于写作。 After done this, I made new migration file that adding new table and run it. 完成此操作后,我创建了新的迁移文件,添加新表并运行它。 It was successful, 它很成功,

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

However, when I checked mysql database using shell, there was no new table. 但是,当我使用shell检查mysql数据库时,没有新表。 I deleted django migrations history and attempted few times more but the result was same. 我删除了django迁移历史记录并尝试了几次,但结果是相同的。 It says migration applied but there was no new table. 它表示已应用迁移,但没有新表。 This is my migration file 这是我的迁移文件

# -*- 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',
        },
    ),
]

I wonder if splited session may affects to do migrations. 我想知道分裂的会话是否会影响迁移。 thanks! 谢谢!

EDIT 编辑

I added my local_settings.py 我添加了我的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'
}
}

If you use multiple DBs in Django, When migrating, you need to check the Database Router that you coded. 如果在Django中使用多个DB,则在迁移时,需要检查编码的数据库路由器。

Check for "allow_migrate" method in your database router class. 检查数据库路由器类中的“allow_migrate”方法。

This is official Django documentation about this issue. 这是关于此问题的官方Django文档。

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

您应该设置数据库名称以迁移其他数据库:

./manage.py migrate --database=write

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM