Django 解決新建表刪除后無(wú)法重新創(chuàng)建等問(wèn)題
起因
同步表的過(guò)程中,我手動(dòng)將數(shù)據(jù)庫(kù)中的一個(gè)表刪除了,此時(shí)再去執(zhí)行命令,發(fā)現(xiàn)不能再數(shù)據(jù)庫(kù)中新建表了
修改了表結(jié)構(gòu)以后執(zhí)行python3 manage.py migrate 報(bào)錯(cuò):
No changes detected
所以進(jìn)數(shù)據(jù)庫(kù)把對(duì)應(yīng)的表刪除了,想著重新生成這張表.
刪除表以后執(zhí)行:
python3 manage.py makemigrationspython3 manage.py migrate
還是不能生成表,提示:No changes detected
處理過(guò)程
一、首先刪除了app對(duì)應(yīng)目錄下的數(shù)據(jù)庫(kù)對(duì)應(yīng)的文件和緩存文件:
$ rm -rf migrations/ __pycache__/
一般可以從本地刪除
重新執(zhí)行:
···$ python3 manage.py makemigrationsNo changes detected /code/django/blogproject~/code/django/blogproject /code/django/blogproject python3 manage.py makemigrations commentsMigrations for ‘comments’:comments/migrations/0001_initial.py- Create model Comment /code/django/blogproject~/code/django/blogproject /code/django/blogproject python3 manage.py migrateOperations to perform:Apply all migrations: admin, auth, blog, comments, contenttypes, sessions, usersRunning migrations:No migrations to apply.···
二、刪除app下面目錄migrations下面除了init.py其他的所有文件
三、最后,刪除migrations中關(guān)于你的app的同步數(shù)據(jù)數(shù)據(jù)庫(kù)記錄
delete from django_migrations where app=‘yourappname’;
重新執(zhí)行生成數(shù)據(jù)庫(kù)命令:
$ python3 manage.py makemigrations commentsNo changes detected in app ’comments’$~/code/django/blogproject$ python3 manage.py migrate commentsOperations to perform: Apply all migrations: commentsRunning migrations: Applying comments.0001_initial... OK
數(shù)據(jù)表順利生成.
結(jié)論
在執(zhí)行
python3 manage.py makemigrationspython3 manage.py migrate
操作的時(shí)候,不僅會(huì)創(chuàng)建0001_initial.py對(duì)應(yīng)的模型腳本,還會(huì)創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)記錄創(chuàng)建的模型.如果想重新生成數(shù)據(jù)庫(kù),需要三個(gè)地方都做刪除.
以上這篇Django 解決新建表刪除后無(wú)法重新創(chuàng)建等問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. PHP驗(yàn)證碼工具-Securimage2. Vue 實(shí)現(xiàn)對(duì)quill-editor組件中的工具欄添加title3. JavaScript實(shí)現(xiàn)簡(jiǎn)單的彈窗效果4. 我所理解的JavaScript中的this指向5. javascript實(shí)現(xiàn)貪吃蛇小練習(xí)6. PHP利用curl發(fā)送HTTP請(qǐng)求的實(shí)例代碼7. Java commons-httpclient如果實(shí)現(xiàn)get及post請(qǐng)求8. PHP單件模式和命令鏈模式的基礎(chǔ)知識(shí)9. 一文帶你徹底理解Java序列化和反序列化10. js實(shí)現(xiàn)碰撞檢測(cè)

網(wǎng)公網(wǎng)安備