Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sqlite

django

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?

like image 397
Dan Avatar asked Feb 10 '17 02:02

Dan


People also ask

Can I delete DB sqlite3?

Like most relational database systems, SQLite does not use the DROP DATABASE command to drop a database and there is no special syntax or steps to drop the database in SQLite. You just have to delete the file manually. Here filename is always unique i.e. database name is always unique and it is case-sensitive.


1 Answers

  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

like image 93
Mohammed Shareef C Avatar answered Sep 28 '22 14:09

Mohammed Shareef C