If I create some groups for my users with admin system, when I make my project in production, do I have to recreate all my groups and reassign permissions ? Or I need to dump database ?
Asked
Active
Viewed 154 times
1 Answers
1
You can serialize the data you created and put it into a data migration that will run after initial schema migrations. Your custom migrations reside in the same folder the generated ones do (yourapp/migrations
).
What you put in the migration is up to you. It can be some SQL (e.g. a dump), or some code that uses historical models to create your objects.
This is a clean solution - you have everything you need for deployment in your migrations.

Ivan
- 5,803
- 2
- 29
- 46
-
I think it's a great idea to create groups and assign permissions to these groups in a migration. But in which folder I have to add my data migrations ? – Alexandre Dec 08 '16 at 14:34
-
@AlexandrePécorilla I edited the answer. But generally, read the whole https://docs.djangoproject.com/en/1.10/topics/migrations/ because you have to pay attention when dealing with migrations. – Ivan Dec 08 '16 at 14:39
-
When you say in `yourapp/migrations` is in the root of project, or in same folder of settings.py urls.py wsgi.py ? – Alexandre Dec 08 '16 at 14:51
-
@AlexandrePécorilla they should be in the folder of a relevant app. If your project is `ride_sharing` and inside you have the main app also called `ride_sharing`, it will be in `ride_sharing/ride_sharing` alongside `settings.py` and `urls.py`. If you have a separate app for user-related classes, you can put it there. – Ivan Dec 08 '16 at 14:59
-
Ok, so I can create a file like this +> http://stackoverflow.com/questions/33485464/right-way-to-create-a-django-data-migration-that-creates-a-group (in second post) – Alexandre Dec 08 '16 at 15:02
-
@AlexandrePécorilla yes, for example. But if you (or someone else) find it more convenient to use the admin and make a dump you can do it too. – Ivan Dec 08 '16 at 15:04