我正在使用Django 1.9+ Photologue3.x来构建一个相册web应用程序。
当我尝试添加照片或图库时,它返回'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然后我检查了模型文件和视图文件。
在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()这似乎是对的。因为它是Django 1.9,所以没有更多的syncdb或clear sql methods可用。我尝试了migrate/makemigrations,sqlmigrates,它们都不起作用。
我的想法是重建sql表,但是如何实现这一点,或者解决这个问题的任何其他方法?
谢谢。
EDIT1:已尝试使用flush命令刷新数据库中的数据,但仍不起作用。
EDIT2:已尝试inspectdb命令,已获取
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'这是否意味着模型中的'slug‘字段与数据库中的实际字段'title_slug’不匹配?
发布于 2016-08-24 10:44:35
尽管syncdb命令已从Django1.9中删除
这里有python manage.py migrate appname --run-syncdb命令。
它将模型与数据库同步。
发布于 2016-08-25 01:02:22
你说Django迁移系统-- "python manage.py migrate“不工作。会发生什么?您是否收到错误消息?
https://stackoverflow.com/questions/39113057
复制相似问题