Django:迁移成功但未创建新表 [英] Django : migration success but not creating new table

查看:72
本文介绍了Django:迁移成功但未创建新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用django迁移来处理数据库.最近,我将会话分为两部分,一个用于阅读,另一个用于写作.完成此操作后,我制作了一个新的迁移文件,该文件添加了新表并运行它.成功了,

I've been using django migration to handle database. 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

但是,当我使用shell检查mysql数据库时,没有新表.我删除了django迁移历史记录,并尝试了几次,但结果是相同的.它说迁移已应用,但没有新表.这是我的迁移文件

However, when I checked mysql database using shell, there was no new table. I deleted django migrations history and attempted few times more but the result was same. 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!

编辑

我添加了我的local_settings.py

I added my 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,则在迁移时,您需要检查编码的数据库路由器.

If you use multiple DBs in Django, When migrating, you need to check the Database Router that you coded.

在数据库路由器类中检查"allow_migrate"方法.

Check for "allow_migrate" method in your database router class.

这是有关此问题的Django官方文档.

This is official Django documentation about this issue.

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

这篇关于Django:迁移成功但未创建新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆