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?
Asked
Active
Viewed 682 times
1

Yusuf
- 2,295
- 7
- 15
- 34
-
2The 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 – Iain Shelvington May 29 '22 at 16:45zero --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
2 Answers
-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
-
The flush command does not delete the database https://docs.djangoproject.com/en/4.0/ref/django-admin/#flush – Iain Shelvington May 29 '22 at 17:00
-
I think your terminal address is false and flush apply for one another database – M.J.GH.PY May 29 '22 at 19:37
-