Forums

django no such column error

Hi,

I deleted a model field (created_date) on my local django models.py .

Some of the migrations and / or pulls from Github to pythonanywhere must have failed, and I got "No such column" error. I then dropped the table on sqlite, deleted all migrations files and got "table does not exist".

I managed to recreate all migrations, run makemigrations and migrate until everything is up to date. But I still get the "no such column" error.

db:

pragma table_info('suquiwrites_entry');                                                                                                     
cid         name        type        notnull     dflt_value  pk        
----------  ----------  ----------  ----------  ----------  ----------
0           id          integer     1                       1         
1           title       varchar(20  1                       0         
2           text        text        1                       0         
3           published_  datetime    0                       0         
4           author_id   integer     1                       0         
sqlite>

models.py:

from django.db import models
from django.conf import settings
from datetime import datetime
class Entry(models.Model):
    author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    title = models.CharField(max_length=200)
    text = models.TextField()
    published_date = models.DateTimeField(blank=True, null=True)
    def publish(self, value):
        self.published_date = datetime.strptime(value, "%d-%m-%Y").date()
        self.save()
    def __str__(self):
        return self.title

Error code : Exception Value: no such column: suquiwrites_entry.created_date

Tia

Are you running your web app with the same database you applied migrations to?

I don't know what that means / how to check for that.

Do you have one settings file?

yes - do you want me to post it?

What I did in the end was to manually recreate all migration files in the bash console, using touch to create and nano to copy paste the content from my local files into the pythonanywhere files. Then I rerun migrate and even though I got the warning Entry has no field named 'created_date', the page is now deployed.

However, now when I run any other command, it's asking me to rerun migrations and I get the same error.

I'm a bit confused -- in the model file you shared in your first post, there is no field called created_date. You'll need to have one there if you want to use it.