【发布时间】:2016-05-31 08:39:46
【问题描述】:
在一些错误之后,我删除了我的数据库,删除了所有迁移文件(我离开了 init.py)。 现在,当我跑步时
python migrate.py makemigrations // It creates migrations correctly
python migrate.py migrate // It outputs "app.0001_initial OK"
但绝对NO table(与我的应用相关)是创建的。只有那些与 django 相关的。 并且在迁移表中,我的应用程序迁移被标记为已完成但没有创建表,就像我说的那样,非常不愉快。
这是我的迁移文件的摘录:
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-02-18 21:59
from __future__ import unicode_literals
import colorful.fields
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Client',
fields=[
('id', models.AutoField(db_column='idtblclients', primary_key=True, serialize=False)),
('genre1', models.CharField(blank=True, max_length=10)),
('prenom1', models.CharField(blank=True, max_length=45)),
('nom1', models.CharField(blank=True, max_length=45)),
('genre2', models.CharField(blank=True, max_length=10)),
('prenom2', models.CharField(blank=True, max_length=45)),
('nom2', models.CharField(blank=True, max_length=45)),
('courriel', models.CharField(blank=True, max_length=45)),
('langue', models.CharField(blank=True, max_length=1)),
('numtel1', models.CharField(blank=True, db_column='NumTel1', max_length=20)),
('numtel2', models.CharField(blank=True, db_column='NumTel2', max_length=20)),
('numcivique', models.CharField(blank=True, db_column='NumCivique', max_length=15)),
('rue', models.CharField(blank=True, db_column='Rue', max_length=45)),
('ville', models.CharField(blank=True, db_column='Ville', max_length=45)),
('codepostal', models.CharField(blank=True, db_column='CodePostal', max_length=45)),
('timestamp', models.DateTimeField(blank=True, db_column='Timestamp', null=True)),
('zone', models.CharField(blank=True, db_column='Zone', max_length=45)),
],
options={
'db_table': 'tblclients',
'managed': False,
},
),
....
你知道如何解决它吗?
【问题讨论】:
-
你在
settings.py添加了应用吗? -
是的,当然。当我运行 migrate 时,django 告诉我“app.0001_initial OK”这应该意味着迁移已经完成(虽然他们还没有像我说的那样完成)
-
我忘了告诉迁移忽略了我的应用迁移文件(我复制的那个)中的所有迁移,但最后一个是一个表,它与第一个其他表具有外键。所以mysql输出错误。
-
试试
python manage.py makemigrations <appname_thats_missing_tables>和python manage.py migrate <appname_thats_missing_tables> -
啊,你是对的。我怎么没看到!谢谢。
标签: python mysql django migration