亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

解決Django migrate No changes detected 不能創(chuàng)建表的問題

 更新時(shí)間:2018年05月27日 15:55:03   作者:hanglinux  
今天小編就為大家分享一篇解決Django migrate No changes detected 不能創(chuàng)建表的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

起因

修改了表結(jié)構(gòu)以后執(zhí)行python3 manage.py migrate 報(bào)錯(cuò):

django.db.utils.OperationalError: (1091, "Can't DROP 'email'; check that column/key exists")

所以進(jìn)數(shù)據(jù)庫把對(duì)應(yīng)的表刪除了,想著重新生成這張表.

刪除表以后執(zhí)行:

python3 manage.py makemigrations
python3 manage.py migrate

還是不能生成表,提示:No changes detected

處理過程

首先刪除了app對(duì)應(yīng)目錄下的數(shù)據(jù)庫對(duì)應(yīng)的文件和緩存文件:

$ rm -rf migrations/ __pycache__/

重新執(zhí)行:

$ python3 manage.py makemigrations
No changes detected
$~/code/django/blogproject$ python3 manage.py makemigrations comments
Migrations for 'comments':
 comments/migrations/0001_initial.py
 - Create model Comment
$~/code/django/blogproject$ python3 manage.py migrate
Operations to perform:
 Apply all migrations: admin, auth, blog, comments, contenttypes, sessions, users
Running migrations:
 No migrations to apply.

進(jìn)入數(shù)據(jù)庫發(fā)現(xiàn)仍然沒有生成表.

然后發(fā)現(xiàn)有一張django_migrations表,里面記錄這有關(guān)創(chuàng)建表的記錄,刪除對(duì)應(yīng)的數(shù)據(jù)表:

delete from django_migrations where app='yourappname';

重新執(zhí)行生成數(shù)據(jù)庫命令:

$ python3 manage.py makemigrations comments
No changes detected in app 'comments'
$~/code/django/blogproject$ python3 manage.py migrate comments
Operations to perform:
 Apply all migrations: comments
Running migrations:
 Applying comments.0001_initial... OK

數(shù)據(jù)表順利生成.

結(jié)論

在執(zhí)行

python3 manage.py makemigrations python3 manage.py migrate

操作的時(shí)候,不僅會(huì)創(chuàng)建0001_initial.py對(duì)應(yīng)的模型腳本,還會(huì)創(chuàng)建一個(gè)數(shù)據(jù)庫記錄創(chuàng)建的模型.如果想重新生成數(shù)據(jù)庫,需要兩個(gè)地方都做刪除.

以上這篇解決Django migrate No changes detected 不能創(chuàng)建表的問題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論