Search code examples
pythondjangomigrate

Django : How can I put the initial data into database by editting migrations file?


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...


Solution

  • 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