0

This morning I have had a complete meltdown with my django progect :( I have been fiddling with models and then got an error. Cut a long story short I am now in a mess and absolutely nothing works.

The good news is that the content of the database is only test data so can all be lost. I did a search on stackoverflow and found the following link:

Django 1.8: Create initial migrations for existing schema

Below is a list of all my migration folders:

meta\migrations straightred\migrations allauth\account\migrations allauth\socialaccount\migrations allauth\socialaccount\providers\openid\migrations

That all makes sense but I do have 2 quick questions:

1) Do I remove the migrations for the project alluth? (a social network login app) 2) The allauth app also has some directories named: south_migrations. Should these also be deleted?

Many thanks in advance, any help would be appreciated as I am now staring at a couple of months work not running because of a database hiccup :(

Community
  • 1
  • 1
Alan Tingey
  • 835
  • 11
  • 39
  • 2
    There's no need to remove the migrations. Just delete the database and then run the migrations again. – Daniel Roseman Sep 10 '16 at 09:06
  • I did try that but I think I had corrupted / fiddled with my migrations so needed a completely clean slate I think. Appreciate the response. If I had not of been a wally I couldve used your idea. – Alan Tingey Sep 10 '16 at 09:34
  • what i did just now is i just delete the db.sqlite3 file and everything works well – Ritik Kumar Jun 15 '21 at 17:13

2 Answers2

0

To Delete all tables:

manage.py sqlclear

To Delete all Data:

manage.py flush

To recreate all the tables:

manage.py syncdb

Hope this helps.

almost a beginner
  • 1,622
  • 2
  • 20
  • 41
  • 2
    These days I simply delete the db.sqlite3 file, which basically deletes the whole database, and then use 'manage.py migrate --run-syncdb' to recreate the database. I never use the commands on my answer so I wouldn't know if they have changed or not. – almost a beginner Jun 20 '18 at 04:40
  • 1
    Who uses sqlite with a production Django system? Needless to say deleting a file won't work with postgresql or mysql. Still for what it' worth Django 2.2 and later support `manage.py sqlflush` which prints teh SQL for a complete database reset that you have to execute yourself, `manage.py flush` states explicitly that it is not a complete reset (in infer it clears the data but leaves the autoid sequencers but sqlflush explicty resets them to 1. – Bernd Wechner Oct 12 '20 at 05:30
0

Typically your reverse migrations fail because the data doesn't fit the tables anymore. So another option is to first flush (delete) your data and then undo all your migrations.

So:

./manage.py flush

and then

./manage.py migrate <appname> 0001_initial

You can then delete or fix whatever migrations were broken, and try again with:

./manage.py migrate

dhr_p
  • 2,364
  • 1
  • 22
  • 19