I'm using PostegreSQL.
What I've tryed already:
python manage.py flush
python manage.py makemigrations
python manage.py migrate
python manage.py makemigrations app
python manage.py migrate app
python manage.py migrate --run-syncdb
There aren't any effect. The table have no recently added columns.
Have no importaint data in tables, can remove it.
Delete all migration files (except the init.py files) and database, rerun makemigrations and migrate.
Remove all DB tables.
Remove all migration files from migrations directory.
python manage.py makemigrations
python manage.py migrate
Related
I have django application, where I wanted to export all migration from my project , auth and admin to sql query. I am able to do
python manage.py sqlmigrate myapp 0001
However, I want to export all migration at same time rather than explicitly righting loops. Is there any package or tool that i can use for this.
you can use squashmigrations command
python manage.py squashmigrations <appname> <squashfrom> <squashto>
and press y
Delete all the before migration files
then run the following command
python manage.py sqlmigrate <appname> <squash_generated_migartion_file>
if you wanted to see the sql for auth migrations
python manage.py sqlmigrate auth 0001_initial
First make sure you are on directory with manage.py file i.e. project directory then, you can do
python manage.py makemigrations
and then run
python manage.py migrate or python manage.py sqlmigrate
I am not able to search and migrate that 1 unapplied migration.
Please help me out
run this "./manage.py makemigrations" again and migrate again.
"./manage.py migrate"
First check migrations list
python manage.py showmigrations --list
In either case, there will be an [X] to show which migrations have been applied.
If you have unapplied migrations the run the command
python manage.py makemigrations
python manage.py migrate
Run python manage.py migrate
If it doesn't work... then delete all files from migrations folder except init.py the go to database and find migrations table, delete all entries. Then again run python manage.py migrate
When I click in my table in http://127.0.0.1:8000/admin/, I see this error:
OperationalError at /admin/home/table/
no such table: home_table.
I ran Python manage.py makemigrations home, Python manage.py makemigrations and Python manage.py migrate but they didn't work.
If you're using sqlite then:
Try unapply all the migrations using using command:
python manage.py appname zero
Then apply the migrations command again. If it still doesn't work then delete your sqlite db and run migrations again. It will work.
I have a production web project running with a decent amount of data in the MySQL db. I am trying to update the database with some changes to an app called "enterlink." I've made new elements in the existing models and created new models altogether. Before this migration, I have never touched the schema of the db since originally running syncdb to create it. When I run: "python manage.py makemigrations enterlink" the below output appears(pic). My question is, why is this happening? The DB already includes all the models that it lists in the picture so why is it registering those lists of models? When I go to finish the migration by doing "python manage.py migrate" or "python manage.py migrate --fake enterlink" (pic again), I get an output shown but my database schema remains identical to the old db and any new code generates errors. Can anyone tell me what is likely the problem? I would be really appreciative of any advice. It's been very frustrating since I'm not sure what I'm missing.
What you have done is that you have ran the command python manage.py syncdb before running python manage.py makemigrations myapp and python manage.py migrate myapp. That is why syncdb created the database schema and the migration was faked because schema already exists. I will suggest to use python manage.py makemigrations myapp and python manage.py migrate myapp and not to use syncdb as its deprecated in Django 1.7.
If you change anything in your model, just run makemigrations and migrate command. Syncdb isn't necessary.
This question and relevant answers are intriguing me. Thus I want to share my experience on maintaining live database and migrations.
Tested in django1.5.5
Initializing the database:
./manage.py syncdb --noinput
./manage.py migrate
./manage.py syncdb
Now I have created the database.
Doing a migration for an app:
./manage.py schemamigration myapp --initial
./manage.py migrate myapp --fake
Now do necessary changes in your model
./manage.py schemamigration myapp --auto
./manage.py migrate myapp
Im newbie for schemamigration too, but i will explain how it works for me:
First you create app and then
./manage.py sycndb, so tables are created then you can
./manage.py makemigrations myapp --initial
so now initial migrations are created and you should apply them
./manage.py migrate myapp
now you can change your models : add,change fields, anything you want and then
./manage.py makemigrations myapp --auto
this will create migrations for changes and now you need to apply them
enter code here./manage.py migrate myapp
so this actually will create new tables in db
I just did:
python manage.py schemamigration TestDBapp1 --initial
python manage.py schemamigration TestDBapp1 --auto
Successfully.
But if I enter: python manage.py migrate TestDBapp1
I get this: sqlite3.OperationalError: table "TestDBapp1_xyz" already exists
What could be the problem?
I suspect that you already executed syncdb which created the tables. South tries to create them again during migrate and naturally the database complains.
To avoid this you have to tell South to "fake" the initial migration.
python manage.py migrate TestDBapp1 --fake
As the name indicates this pretends to migrate. Note that this is an one time step. South will handle your future syncdb and migrate without requiring --fake.