我正在使用django制作博客。我创建了一个名为应用博客,并在models.py我创建了下面的模型中,在这个博客上的文章:异常类型:OperationalError - 异常值:no such column:blog_article.slug
class Article(models.Model):
title = models.CharField(max_length = 100, unique=True)
slug = models.SlugField(max_length=100, unique=True)
author = models.CharField(max_length = 100)
COUNTRIES = (
("fr", "france"),
("ge", "germany"),
)
nationality = models.CharField(choices= COUNTRIES, max_length = 20)
publication_date = models.DateTimeField()
content = models.TextField()
def __unicode__(self):
return '%s' % self.title
@permalink
def get_absolute_url(self):
return ('view_article', None, { 'slug': self.slug })
在admin.py我做了以下内容,才能有蛞蝓预置了标题:
class ArticleAdmin(admin.ModelAdmin):
exclude = ['posted']
prepopulated_fields = {'slug': ('title',)}
我已经跑蟒蛇manage.py makemigrations和迁移几次,试图壁球迁移正如我在其他职位在这里找到。当我运行makemigrations我得到:“没有检测到变化”。当我运行migrate我得到“没有迁移申请”。
然而,当我的runserver并进入管理界面,以增加新的文章,填写“标题”现场,看到自动填写(由于预填充)的蛞蝓领域,并希望SAVE,这里是我得到的:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/blog/article/add/
Django Version: 1.9.4
Python Version: 2.7.11
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog.apps.BlogConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in wrapper
541. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in inner
244. return view(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in add_view
1437. return self.changeform_view(request, None, form_url, extra_context)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapper
67. return bound_func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in bound_func
63. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in inner
184. return func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in changeform_view
1370. if form.is_valid():
File "/Library/Python/2.7/site-packages/django/forms/forms.py" in is_valid
161. return self.is_bound and not self.errors
File "/Library/Python/2.7/site-packages/django/forms/forms.py" in errors
153. self.full_clean()
File "/Library/Python/2.7/site-packages/django/forms/forms.py" in full_clean
364. self._post_clean()
File "/Library/Python/2.7/site-packages/django/forms/models.py" in _post_clean
402. self.validate_unique()
File "/Library/Python/2.7/site-packages/django/forms/models.py" in validate_unique
411. self.instance.validate_unique(exclude=exclude)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in validate_unique
922. errors = self._perform_unique_checks(unique_checks)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in _perform_unique_checks
1017. if qs.exists():
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in exists
651. return self.query.has_results(using=self.db)
File "/Library/Python/2.7/site-packages/django/db/models/sql/query.py" in has_results
501. return compiler.has_results()
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in has_results
819. return bool(self.execute_sql(SINGLE))
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
848. cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/utils.py" in execute
79. return super(CursorDebugWrapper, self).execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/utils.py" in __exit__
95. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Library/Python/2.7/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
323. return Database.Cursor.execute(self, query, params)
**Exception Type: OperationalError at /admin/blog/article/add/
Exception Value: no such column: blog_article.slug**
如果我点击管理界面中的“文章”,我会得到相同的结果。我试图挤压迁移,迁移并再次迁移,但它没有奏效......我到处寻找,并没有找到一个适合我的答案 - 如果您能就此提供一些提示,非常感谢您!
Django的版本?你有没有尝试过'python manage.py makemigrations blog','python manage.py migrate blog'? – ravigadila
Django的版本是:(1,9,4,'final',0) 是的,我也尝试了这些命令,但它们并没有改变结果! –