I have a web app with the following model
class Records(models.Model):
alias = models.CharField(max_length=17, unique=True)
status = models.BooleanField()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.alias
def list_data(self):
return [self.alias, self.status, self.created_at, self.updated_at]
I want some default data to be populated into this model on creation. I went through the documentation and this StackOverflow question for doing the same.
I first ran this command to create a migrations file (0001_initial.py)
python manage.py makemigrations --empty main_app
I then edited the migrations file as follows
0001_initial.py
# Generated by Django 4.0.3 on 2022-04-23 05:57
from django.db import migrations
def add_initial_data(apps, schema_editor):
Records = apps.get_model('main_app', 'Records')
for record in Records.objects.all():
record.alias = f'ACCORD1'
record.status = True
record.save()
for i in range(2,6):
record.alias = f'ACCORD{i}'
record.status = False
record.save()
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.RunPython(add_initial_data)
]
When I run the migrations with the following command
python manage.py migrate
I get the following error
LookupError: No installed app with label 'main_app'.
I tried adding the dependency to the migrations file as follows
dependencies = [
('main_app', '0001_initial')
]
But this gives me the following error
django.db.migrations.exceptions.CircularDependencyError: main_app.0001_initial
I am not sure what I am doing wrong.