We have answer of your question!

100% solved queries, no empty question

Question: How to create a new table using model


So I have this django installation in which there are a bunch of migration scripts. They look like so:


Now I know these are "database building" scripts which will take stuff defined in models.py and run them against the db to "create" tables and stuff.

I want to create a new table(so I created its definition in models.py). For this, I have copied another model class and edited its name and fields and it is all fine. Lets call this new model class 'boom'.

My question is now how do I "create" this boom table using the migration script and the boom model?

I am worried that I might accidentally disrupt anything that is already in DB. How do I run the migration to create only boom table? How do I create a migration script specifically for it?

I know that it has something to do with manage.py and running migrate or runmigration (or is it sqlmigrate?...im confused). While creating the boom table, I dont want the database to go boom if you know what I mean :)

Question author Undefined-variable | Source



First, create a backup of your database. Copy it to your development machine. Try things out on that. That way it doesn't matter if it does go "boom" for some reason.

The first thing to do is

python manage.py showmigrations

This shows all the existing migrations, and it should show that they have been applied with an [X].


python manage.py makemigrations

Makes a new migration file for your new model (name 00004_...).

Then do

python manage.py migrate

to apply it. To undo it, go back to the state of migrations 00003, with

python manage.py migrate <yourappname> 00003
Answer author Remcogerlich

Tickanswer.com is providing the only single recommended solution of the question How to create a new table using model under the categories i.e python , django , django-migrations , . Our team of experts filter the best solution for you.

Related Search Queries:

how to create a database in mysql workbench , how to create table in mysql workbench using query ,

You may also add your answer

Thanks for contributing an answer to Tick Answer!