Django programming error after adding new field

django is throwing a programming error after i added a field to an existing model and redeployed it. it says that projects.location is not found but later in the error page it shows the line where the error occurs but i have not used the location object there. Below is the screenshot of the error:

class Projects(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length = 100, null=False)
    short_description = models.TextField(max_length=500, null=True,)
    description = models.TextField(null=False)
    img1 = models.ImageField(upload_to='project/images/',blank=True,null=True)
    img2 = models.ImageField(upload_to='project/images/',blank=True,null=True)
    img3 = models.ImageField(upload_to='project/images/',blank=True,null=True)
    img4 = models.ImageField(upload_to='project/images/',blank=True,null=True)
    location = models.TextField(null=True)
    objects = models.Manager()
    class Meta:
        verbose_name_plural = 'Projects'; this is where i have used the project.location and its a dynamic url.

def project_details(request, name):

    projs = Projects.objects.all().order_by('-id')
    for proj in projs:

        if name == proj.title:
            context = {
                'project': proj,
            return render(request, 'project_detail.html', context=context)

but the error is shown for my index page.

any further details just ask…

has your migration been successful? check if the field exists in the data base

I suggest the following steps after adding your fields:
1 -py makemigrations.
2- py migrate.
3-py runserver

after that refresh your browser.

@HamaBarhamou @Sirchemaya This happens when i deploy the webapp. it works on my localhost after migration. In my build command to deploy the webapp i’ve added commands to make migrations and migrate. I’m deploying it in render and when i deploy, it shows successful makemigrations after which it says no migrations to apply. yes its weird, but as i checked online it says thats what render shows but the migrations will be successfull. ive added the render log below:

even so, i’ve not used location field in my index page yet it shows error in that page.

Jeez…Solved…! I mean not technically solved. i redeployed it more than 10 times yesterday and it was showing the programming error everytime. Today to take the render logs screenshot, i redeployed the webapp again and it ran with zero error :exploding_head:.

Still wondering why django threw the error the whole day yesterday…

Thanks everyone for your support.

Make sure that your local and production environments are identical.
Go back to the model that worked without adding the field that caused the error.
Then analyze your migration files to determine which migration caused the error, and delete it as well as any other migration files generated as a result. Then run the migration again, which should work in principle.

I say check the fields in your database to confirm whether your new field is present or not. This helps diagnose your problem. I think it’s not created.

@HamaBarhamou I guess the issue was with render. Because as I redeployed the same file today it worked with zero error.