2

I'm trying to set an imageField for upload an image on the admin page, but this error raises.

no such column: series_serie.serie_cover

This is the model:

class Serie (models.Model):
    serie_name = models.CharField(max_length=100)
    serie_cover = models.ImageField(upload_to='/')

    def __str__(self):
        return (self.serie_name)

This is migration file:

        migrations.CreateModel(
        name='Serie',
        fields=[
            ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ('serie_name', models.CharField(max_length=100)),
            ('serie_cover', models.ImageField(upload_to=b'')),
        ],

I've made the following:

  1. python manage.py flush
  2. python manage.py makemigrations
  3. python manage.py migrate

Then I try to access the Serie model from admin side but got that error.

What I could do?

Thanks.

Lechucico
  • 1,914
  • 7
  • 27
  • 60

2 Answers2

0

In your model, you have the field named serie_image, yet in your migration you are attempting to apply the row to the table with a name of serie_cover. This will not work.

You can either change the name on the model to match the migration you are attempting to apply, or you can change the migration to match the model.

Like this:

class Serie (models.Model):
    serie_name = models.CharField(max_length=100)
    serie_cover = models.ImageField(upload_to='/')

    def __str__(self):
        return (self.serie_name)

 migrations.CreateModel(
    name='Serie',
    fields=[
        ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
        ('serie_name', models.CharField(max_length=100)),
        ('serie_cover', models.ImageField(upload_to=b'')),
    ],

Or this:

class Serie (models.Model):
    serie_name = models.CharField(max_length=100)
    serie_image = models.ImageField(upload_to='/')

    def __str__(self):
        return (self.serie_name)

 migrations.CreateModel(
    name='Serie',
    fields=[
        ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
        ('serie_name', models.CharField(max_length=100)),
        ('serie_image', models.ImageField(upload_to=b'')),
    ],
gallen
  • 1,252
  • 1
  • 18
  • 25
  • Can you provide the appropriate section of your admin.py file? I didn't notice at first this was an issue with the admin, not the migration. – gallen Feb 20 '17 at 15:37
0

I solved it removing the file 'db.sqlite3' and re generating it with makemigrations. For some reason the name was stuck there and I couldn't change it.

Lechucico
  • 1,914
  • 7
  • 27
  • 60