这是我一直在做的事情,我想这不是正确的解决方案:
- 修改我的模型
- 删除
db.sqlite3
文件 - 启动
makemigrations
,然后启动migrate
如果我不删除db.sqlite3
文件,当我尝试运行makemigrations
然后migrate
:
manage.py@pyweb > makemigrations
"C:Program Files (x86)JetBrainsPyCharm 4.5.3binrunnerw.exe" C:Python34python.exe "C:Program Files (x86)JetBrainsPyCharm 4.5.3helperspycharmdjango_manage.py" makemigrations C:/Users/Olivier/PycharmProjects/pyweb
No changes detected
Process finished with exit code 0
manage.py@pyweb > migrate
"C:Program Files (x86)JetBrainsPyCharm 4.5.3binrunnerw.exe" C:Python34python.exe "C:Program Files (x86)JetBrainsPyCharm 4.5.3helperspycharmdjango_manage.py" migrate C:/Users/Olivier/PycharmProjects/pyweb
Operations to perform:
Synchronize unmigrated apps: staticfiles, messages, produits
Apply all migrations: sessions, auth, contenttypes, admin
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
No migrations to apply.
Process finished with exit code 0
我错过了什么步骤来避免删除db文件?
更改模型后,您只需执行
python manage.py makemigrations your_app
然后用
python manage.py migrate
这样做你不必删除你的数据库。我希望这对你有所帮助。但是不要忘记在对模型应用更改后运行makemigration