Search code examples
pythondjangophotologue

Django 1.9 + Photologue: no such column


I am using Django 1.9+ Photologue 3.x to build a photo gallery web app.

When I am trying to add photo or gallery, it returns 'NO SUCH COLUMN EXCEPTION'

Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/photologue/gallery/
Django Version: 1.9.5
Exception Type: OperationalError
Exception Value:    
no such column: photologue_gallery.slug
Exception Location: //anaconda/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py in execute, line 323
Python Executable:  //anaconda/bin/python
Python Version: 2.7.12

Then I have checked the model file and view file.

In model.py

@python_2_unicode_compatible
class Gallery(models.Model):
    date_added = models.DateTimeField(_('date published'),
                                      default=now)
    title = models.CharField(_('title'),
                             max_length=250,
                             unique=True)
    slug = models.SlugField(_('title slug'),
                            unique=True,
                            max_length=250,
                            help_text=_('A "slug" is a unique URL-friendly title for an object.'))
    description = models.TextField(_('description'),
                               blank=True)
    is_public = models.BooleanField(_('is public'),
                                default=True,
                                help_text=_('Public galleries will be displayed '
                                            'in the default views.'))
    photos = SortedManyToManyField('photologue.Photo',
                               related_name='galleries',
                               verbose_name=_('photos'),
                               blank=True)
    sites = models.ManyToManyField(Site, verbose_name=_(u'sites'),
                               blank=True)

    objects = GalleryQuerySet.as_manager()

It seems to be right. Since it is Django 1.9, no more syncdb or clear sql methods are available. And I tried migrate/makemigrations, sqlmigrates and none of them works.

My idea is to rebuild the sql table but how to achieve this, or any other approaches to solve this issue?

Thank you.

EDIT1: Tried flush command to flush the data in db, but still not working.

EDIT2: Tried inspectdb command, got

class PhotologueGallery(models.Model):
    id = models.IntegerField(primary_key=True)  # AutoField?
    date_added = models.DateTimeField()
    title = models.CharField(unique=True, max_length=100)
    title_slug = models.CharField(unique=True, max_length=50)
    description = models.TextField()
    is_public = models.BooleanField()
    tags = models.CharField(max_length=255)

    class Meta:
        managed = False
        db_table = 'photologue_gallery'

Does it mean that the 'slug' field in model doesn't match the actual field 'title_slug' in the database?


Solution

  • Although syncdb command has removed from Django 1.9

    There is python manage.py migrate appname --run-syncdb command.

    Which sync the model with the database.