Niclas Nilsson
Niclas Nilsson

Reputation: 5901

Fails to Implement orderedmodel

I'm trying to implement orderedmodel from here: https://github.com/kirelagin/django-orderedmodel

But it fail with DatabaseError Exception Value: no such column: qrgame_place.order

The documentation says nothing about that the model should contain the field order so I suppose the parent class is supposed to implement that field? [EDIT: Yeah, it is. Tried that...]

Here are some of the important snippets from the django files:

# models.py

import hashlib
import random
from django.db import models
from orderedmodel import OrderedModel


class Place(OrderedModel):
    name = models.CharField(max_length=100)
    clue = models.CharField(max_length=300)
    code = models.CharField(max_length=7, editable=False)

    def __unicode__(self):
        return self.name

    def save(self):
        # Need a secret identifier for url. Using a hashed name (which
        # is also secret until found. So no need to obscure more)
        if not self.id:
            hashsrc = self.name.encode('utf-8')
            self.code = unicode(hashlib.sha1(hashsrc).hexdigest()[:7])
        super(Place, self).save()



# admin.py

from django.contrib import admin
from qrgame.models import Place
from orderedmodel import OrderedModelAdmin


class PlaceAdmin(OrderedModelAdmin):
    list_display = ['name', 'clue', 'reorder']

admin.site.register(Place, PlaceAdmin)



# settings.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'orderedmodel',
    'qrgame',
)

I have ran python manage.py syncdb after implemented this.

Any idea what's wrong? (Django version is (1, 4, 1, 'final', 0))

Upvotes: 0

Views: 222

Answers (1)

alex vasi
alex vasi

Reputation: 5344

syncdb can't alter existing tables at the moment. You can do the following:

  • drop table manually and than run syncdb
  • run manage.py reset qrgame but all data of the qrgame app will be lost
  • use any existing django db migration solutions, like South
  • manually add column to the table (hints: manage.py dbshell will give you db REPL. You can get column definition from manage.py sqlall qrgame
  • dumpdata and loaddata commands can be helpful for saving and restoring existing data between schema changes

Upvotes: 2

Related Questions