夹层/ Django 1.10迁移:数据库表与迁移不相关 [英] Mezzanine/Django 1.10 migrations: Database tables does not much with migrations

查看:204
本文介绍了夹层/ Django 1.10迁移:数据库表与迁移不相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用夹层(Django 1.10),所以我看不到 db.sqlite3



我搜索了类似的问题,我提供的解决方案大部分都没有效果。



我创建了一个新的模型,后来决定添加一个新的字段。我做了python manage.py makemigrations,当我看着我的迁移文件夹,它在那里;新的领域存在。现在,当我运行应用程序并查看管理员时,它给了我错误,它说没有这样的列存在。因此,我认为,我的数据库不与我的迁移进行同步。



这就是我所做的:
1.删除迁移文件夹中的所有内容,重新创建了 init .py。



1.1运行 python manage.py makemigrations< app_name>



1.2 run python manage.py migrate< app_name>



1.3运行实际上,我可以将我的模型重命名为具有相同字段的不同名称,但是,然而,有时Django会给出错误,例如不存在这样的表。这样做还是安静的,因为如果我重命名我的模型,我必须在每个导入模型的文件中重命名它,例如在admin.py,forms.py,views.py等中。



我听说过南方,但不适用于Django 1.10。



请帮忙。谢谢!

解决方案

我刚刚解决了这个问题。由于我使用夹层,所以数据库的名称是不一样的。查找dev.db,它将位于manage.py的同一个文件夹中。然后,删除它。然后,再次运行makemigrations和迁移。然后(我希望)它会工作。


I am using Mezzanine (Django 1.10) so I can't see a "db.sqlite3"

I searched similar questions as mine and most of the solutions provided were not effective.

I created a new model and later decided to add a new field. I did "python manage.py makemigrations ", and when I looked at my migrations folder, it's there; the new field exists. Now, when I ran the app and looked into admin, it gave me error where it said "No such column exists". Therefore, I think, my database is not synced with the migrations I have.

This is what I did: 1. deleted everything in the migration folder and recreated the "init.py".

1.1 ran "python manage.py makemigrations <app_name>"

1.2 ran "python manage.py migrate <app_name>"

1.3 ran "python manage.py runserver"

I can actually just rename my model into a different name with the same fields, however, sometimes Django would give error such as "no such table exist". It would also be quiet tedious to do because if I rename my model, I have to rename it in every file where I have imported the model such as in admin.py, forms.py, views.py, etc.

I heard about South, but its not applicable to Django 1.10.

Please Help. Thank you!

解决方案

I just solved this problem. Since I am using Mezzanine then the name of the database is not the same. Look for "dev.db" which would be located at the same folder of your "manage.py". Then, delete it. Then, run "makemigrations" and "migrate" again. Then (I hope)it would work.

这篇关于夹层/ Django 1.10迁移:数据库表与迁移不相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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