Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
839 views
in Technique[技术] by (71.8m points)

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

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 database with the correct spelling in model.

I've tried to use the suggestions in the this article but the table still exists after I follow the commands outlined there.

Anyone have a quick way to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...