1

I am working with Django v4.* which I connected it to Postgres DB on the localhost, I have created my model (Article) then makemigrations then migrate then I have changed the model by adding extra field, as a result it didn't take effect so I have deleted the table and all the migrations files in articles/migrations folder apart of the __init__.py file, then I did makemigrations then migrate it create a new file 0001_initial.py but its not creating a new table into the DB, unless I drop the whole DB, which is not ideal in the production env! I am wondering why Django is unable to create the table back again? and how I can get it created as a new table?

Yusuf
  • 2,295
  • 7
  • 15
  • 34
  • 2
    The migrations table will still have the entry saying that the migration `.0001_initial` has been applied. You can mark it as not applied by running the command `python manage.py migrate zero --fake`. You can just run `python manage.py migrate zero` to delete all the tables via Django instead of manually deleting tables and not have this issue – Iain Shelvington May 29 '22 at 16:45

2 Answers2

-1

Roll back to your initial migration by running below command:

python manage.py migrate --fake <appname> 0001

Followed by:

python manage.py migrate <appname>

MohitC
  • 4,541
  • 2
  • 34
  • 55
-2

Just delete your database with

python manage.py flush

And delete migrations files

You may have mistyped the directory in the terminal

M.J.GH.PY
  • 75
  • 7