I believe that Django migrations are a bit of a mystery and tend to prefer external tools (like Liquibase).
However, I just ran into the "No migration to apply" problem. I also tried deleting the migrations folder, which does not help.
If you already deleted the migrations folder, here was an approach that worked for me.
First create new โcleanโ migrations:
$ python manage.py makemigrations foo Migrations for 'foo': dashboard/foo/migrations/0001_initial.py - Create model Foo - Create model Bar
Then look at SQL and see if it looks reasonable:
$ python manage.py sqlmigrate foo 0001 BEGIN; -- -- Create model Foo -- CREATE TABLE "foo" ("id" serial NOT NULL PRIMARY KEY, ... "created_at" timestamp with time zone NOT NULL, "updated_at" timestamp with time zone NOT NULL); CREATE INDEX "..." ON "foo" (...); COMMIT;
Then apply the execution of the same SQL in your database.
I use Postgres, but it will be similar to other engines.
One way is to write the contents to a file:
$ python manage.py sqlmigrate foo 0001 > foo.sql $ psql dbname username < foo.sql BEGIN CREATE TABLE CREATE INDEX COMMIT
Another is a direct SQL query:
$ python manage.py sqlmigrate foo 0001 | psql dbname username
Or copy and paste it, etc.
Andrew E
source share