Richard
Richard

Reputation: 65530

Django: handle migrations for an imported database?

I'm working in Django 1.8 and trying to set up an existing project. I've inherited a database dump, plus a codebase.

I've imported the database dump successfully.

The problem is that if I try to run migrate against the imported database I then get errors about columns already existing, because the database is already at the end state of all the migrations:

 django.db.utils.ProgrammingError: column "managing_group_id" 
   of relation "frontend_pct" already exists

How can I resolve this?

I would like to be able to add new migrations from this point, and I would also prefer not to delete all the existing migrations.

Basically I need a way to say "skip straight to migration 36, and continue from there".

Upvotes: 1

Views: 162

Answers (2)

Mushahid Khan
Mushahid Khan

Reputation: 2834

I think your migrations problem solved by the previous Answer. Therefore I'm adding a link below...

If you just started django 1.7 and above then

Here I'ld like to add a link Django Migration How works

That will useful where I think.

Upvotes: 1

Alasdair
Alasdair

Reputation: 308839

Use the --fake option to tell Django that each app in the database has already been migrated to a particular migration. For example, for the app that has been migrated to migration 36:

./manage.py migrate --fake myapp 0036_your_migration_name

You'll have to do this for each installed app.

Upvotes: 0

Related Questions