Reputation: 45
I added 'models' and created a file using 'makemigrations'. I want to have the initial data in the database at the same time as 'migrate'. However, no matter how much I edit the 'migrations' file, there is an error that says no because there is no 'table' in the database before 'migrate'. Help me...
Upvotes: 0
Views: 144
Reputation: 786
This will help https://docs.djangoproject.com/en/2.2/topics/migrations/#data-migrations
This is also the nice blog where you can create data migration similar to how you create database migration. https://simpleisbetterthancomplex.com/tutorial/2017/09/26/how-to-create-django-data-migrations.html
Upvotes: 2
Reputation: 61
You might want to look into Django data migrations: https://docs.djangoproject.com/en/2.2/topics/migrations/#data-migrations
In the operations, run your actual table creation before running data initialization. Please give code example if you run into problems.
Upvotes: 0