PiWo
PiWo

Reputation: 620

Django migrations - default entries (inserting rows in tables as part of migration)

Background:

I'm dealing with quite complex django application and I'm looking for a way to make my life a little bit easier.

One of the models (tables) serves as source of "options" for most "select lists" in the system (simple field <-> dictionary construct). It should always be populated with the default values and/or extenden when the there are new entries provided with a new version of the system.

I manage it all now manually so:

  1. I run migrations for the main app
  2. Unload the dictionary tables from the dev enviroment
  3. Insert them manually into the enviroment I'm currently upgrading
  4. I migrate the rest of the apps which may contain refferences to the dictionary tables

All of this because of default values provided in ForeignKeys.

Actual Question:

Is it possible to add table entries (table content) to the makemigrations process for particular tables??

Upvotes: 4

Views: 3529

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599610

Yes, you can do anything you like in a migration via the RunPython operation. This is called a data migration and is fully documented.

Upvotes: 3

Related Questions