Database migrations¶
Plata does not include database migrations. The reason for that is that
Django does not support the concept of lazy foreign keys. Because you’re
free to choose any model as product for Plata (configurable using
PLATA_SHOP_PRODUCT
) we do not know beforehand, how the database
constraints for the order item product foreign key should look
beforehand. Because of that it’s easier for everyone to just not include
any migrations and instead provide instructions in the release notes
when a database migration has to be performed.
Note
This isn’t strictly true anymore now that Django supports swappable models. This guide has been written in 2012 long before Django officially supported a swappable user model.
The following issues on Github will shed further light upon this issue:
- https://github.com/matthiask/plata/issues/33
- https://github.com/matthiask/plata/issues/27
- https://github.com/matthiask/plata/issues/26
Note
Despite not bundling database migrations, using them is very much recommended and officially supported. Any pitfalls will be documented here and in the release notes.
Configuring migrations for Plata¶
Since the migrations are project-specific, the migration files should be added to your apps, and not to Plata itself. This can be achieved using the following setting:
MIGRATION_MODULES = {
'contact': 'yourapp.migrate.contact',
'discount': 'yourapp.migrate.discount',
'stock': 'yourapp.migrate.stock', # If you're using stock tracking
'shop': 'yourapp.migrate.shop',
}
You’ll have to add a folder migrate
in your app containing only an
empty __init__.py
file for these instructions to work. After that
run makemigrations
on each Plata app and you’re hopefully done.
Note
You can use any other name for the migrate
folder except for
migrations
.