我使用Django 1.10
学校/模特
class School(models.Model):
name = models.CharField(max_length=10,null=False)
school_id = models.CharField(max_length=8,null=False)
weather = models.ForeignKey(Weather,related_name="school")当我通过添加eng_name = models.CharField(max_length=50,null=False)来修改学校的课程时
我先删除了迁移文件。
在运行命令之后:
python manage.py makemigrations school
python manage.py migrate --fake-initial school
python manage.py migrate school
用于migrate的消息都是
Operations to perform:
Apply all migrations: school
Running migrations:
No migrations to apply.但数据库没有更新。
造成这一问题的可能原因是什么?
UPDATAE
迁移/0001_initial.py
class Migration(migrations.Migration):
initial = True
dependencies = [
('weather', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='School',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=10)),
('eng_name', models.CharField(max_length=50)),
('school_id', models.CharField(max_length=8)),
('weather', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='school', to='weather.Weather')),
],
),
]python manage.py showmigrations --plan
X weather.0001_initial X school.0001_initial
这两个都是最新的迁移。
发布于 2017-09-29 16:21:33
Django用列(id、app、name、applied)将应用迁移存储在数据库表(django_migrations)中。只需删除行与应用的初始迁移为“学校”应用程序,然后进行迁移。而且,今后不要删除旧的事务文件。使用它们,django将为迁移机制创建正确命名的事务。
https://stackoverflow.com/questions/46489273
复制相似问题