Reputation: 248
For context, I have an application that works perfectly fine locally, after some fiddling with the database. It uses a react frontend, with a django backend for internal api calls. However, on a new, fresh download, with a new, fresh database, I always get an error saying relation "claims" does not exist
, where Claims is the name of a table in my database, in the form of a model.
I have been able to bypass this error by commenting out all code that uses the model, then slowly migrating every single table, one at a time, then uncommenting out the code that uses the model.
This is incredibly tedious, but it works in a local environment. However, as I attempt to push this into production, I am using Heroku, and I am unable to make multiple commits in the same way, as it seems the database gets reset everytime there is a new update.
Am I missing something? I feel as though there must be something I am doing incorrectly here, but I have not been able to find anything other than posts saying to reset all my migrations, and redoing the makemigrations command. This method hasn't worked for me in Heroku, because I need to do each migration individually, as I said before.
For reference, here are my related files: models.py
class Claims(models.Model):
id = models.BigAutoField(primary_key=True)
refId = models.CharField(db_column='refId', unique=True, max_length=10) # Field name made lowercase.
title = models.CharField(max_length=20, blank=True, null=True)
description = models.CharField(max_length=256, blank=True, null=True)
image = models.CharField(max_length=70, blank=True, null=True)
created_at = models.DateTimeField(blank=True, null=True)
start = models.DateTimeField(blank=True, null=True)
end = models.DateTimeField(blank=True, null=True)
distributor = models.CharField(max_length=20, blank=True, null=True)
status = models.TextField(blank=True, null=True, choices=claimStatus.choices, default=claimStatus.active) # This field type is a guess.
class Meta:
managed = True
db_table = 'claims'
unique_together = (('id', 'refId'),)
migrations/0001_initial.py
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Claims',
fields=[
('id', models.BigAutoField(primary_key=True, serialize=False)),
('refId', models.CharField(db_column='refId', max_length=10, unique=True)),
('title', models.CharField(blank=True, max_length=20, null=True)),
('description', models.CharField(blank=True, max_length=256, null=True)),
('image', models.CharField(blank=True, max_length=70, null=True)),
('created_at', models.DateTimeField(blank=True, null=True)),
('start', models.DateTimeField(blank=True, null=True)),
('end', models.DateTimeField(blank=True, null=True)),
('distributor', models.CharField(blank=True, max_length=20, null=True)),
('status', models.TextField(blank=True, choices=[('ACTIVE', 'Active'), ('INACTIVE', 'Inactive'), ('DISCONTINUED', 'Discontinued')], default='ACTIVE', null=True)),
],
options={
'db_table': 'claims',
'managed': True,
'unique_together': {('id', 'refId')},
},
),
]
useClaim.py
from .models import *
claim, created = Claims.objects.get_or_create(
refId = "DROPTEST",
title = "DROPTEST",
description ="DROPTEST",
image = "https://ipfs.io/ipfs/QmcPjQ7iaZ8exuZnH1awHZtkQPyL3TRT1S46wVJxwucay5",
created_at = None,
start = None,
end = None,
distributor = "DROPTEST",
status = claimStatus.active
)
claim.save()
Upvotes: 0
Views: 84
Reputation: 248
Thanks to @AbdulAzizBarkat, I found that the issue was not in the compilation level of the application as I had originally thought. I had code modifying/referencing the models before they were migrated. I tried the ready
method of AppConfig, however that did not work for me. Instead, I took the database initialization and wrote a migration operation instead, and that worked wonderfully.
Upvotes: 1