0

Django I am trying to add a new table/model from Django models to my existing postgres database with tables already but the only solution is to start from scratch again

Solution: Delete migrations, delete all the tables in the postgres database. python manage.py makemigrations, python manage.py migrate

Error: The table does not exist when browsing the drf api or the postgres database after trying to makemigrations and migrate with the new models.

1
  • If you ran migrations, the table would exist. There is no need to delete all the tables. Commented Oct 31, 2019 at 15:23

2 Answers 2

0

Adding additional tables (as a result of creating new models) does not require you to start from scratch or delete any existing data. It would be helpful to have examples of the migrations which fail to apply.

Sign up to request clarification or add additional context in comments.

Comments

0

It looks like your migration files and migrations in the database (djang_migrations table - i hope it is correct table name) are not compatible.

If you are sure that your tables in db and your models are the same (existing migration files mirrors your database tables) and you want SomeModel (for this example) model to be created you can try to:

  1. Clear your django_migrations table - remember to make backup of this table
  2. manage.py migrate --fake (it will only create some rows in django_migrations table)
  3. manage.py makemigrations (it should create migration file for SomeModel model)
  4. manage.py migrate (it will create new table)

Hope it will help :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.