How do I delete DB (sqlite3) in Django 1.9 to start from scratch?

前端 未结 4 1717
庸人自扰
庸人自扰 2020-12-07 15:28

I made a spelling error in my model and now one of my columns is misspelled. I\'d like to drop all tables in the database, fix the error in the model.py, and recreate the da

4条回答
  •  鱼传尺愫
    2020-12-07 15:49

    1. Delete the sqlite database file (often db.sqlite3) in your django project folder (or wherever you placed it)
    2. Delete everything except __init__.py file from migration folder in all django apps (eg: rm */migrations/0*.py)
    3. Make changes in your models (models.py).
    4. Run the command python manage.py makemigrations or python3 manage.py makemigrations
    5. Then run the command python manage.py migrate.

    That's all.

    If your changes to the models are not detected by makemigrations command, please check this answer

提交回复
热议问题