Z
Z
zkweb2015-09-28 16:05:49
Django
zkweb, 2015-09-28 16:05:49

How to create a new table in a database - Django?

New to django. Tell me, please, you need to make a new model in the application + tables in the database.
In model.py, I specified a new model class, with fields, etc.
The question itself: is it necessary to always execute makemigrations and then migrate?
How can I quickly announce a new table and model to django?
That is, the application already has other tables, and when you call migrate, it swears.
django.db.utils.ProgrammingError: relation " table " already exists

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Astrikov, 2015-10-01
@astrikovd

The question itself: is it necessary to always run makemigrations and then do migrate?

Yes, starting from version 1.7 in Django, as far as I remember, tables are created in this way.
python manage.py makemigrations <app_name> 
python manage.py migrate <app_name>

That is, the application already has other tables, and when you call migrate, it swears.
django.db.utils.ProgrammingError: relation "table" already exists

Before making changes to the model, do makemigrations and migrate --fake. Then make changes to the model, again makemigrations and migrate, this time without the --fake flag. The table will be changed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question