我尝试添加我的模型降价但我收到错误。 我的旧models.py:
class Post(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique=True)
excerpt = models.TextField(blank=True, help_text="A small teaser of\
your content")
content = models.TextField()
date_created = models.DateTimeField(auto_now_add=True)
is_published = models.BooleanField(default=True)
objects = models.Manager()
published_objects = PublishedManager()
tags = TaggableManager()
category = models.ForeignKey(Category)
和我的新models.py
class Post(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique=True)
excerpt = models.TextField(blank=True, help_text="A small teaser of\
your content")
content = models.TextField()
contentmarkdown = models.TextField()
date_created = models.DateTimeField(auto_now_add=True)
is_published = models.BooleanField(default=True)
objects = models.Manager()
published_objects = PublishedManager()
tags = TaggableManager()
category = models.ForeignKey(Category)
def save(self):
self.content = markdown.markdown(self.contentmarkdown)
super(Post, self).save() # Call the "real" save() method.
当我使用南方并在此行之后:python manage.py迁移博客 我收到了这个错误:
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/migration/__init__.py", line 213, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/migration/migrators.py", line 235, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/migration/migrators.py", line 310, in migrate_many
result = self.migrate(migration, database)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/migration/migrators.py", line 133, in migrate
result = self.run(migration)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/migration/migrators.py", line 107, in run
return self.run_migration(migration)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/migration/migrators.py", line 81, in run_migration
migration_function()
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/migration/migrators.py", line 57, in <lambda>
return (lambda: direction(orm))
File "/home/ada/mainproject/blog/migrations/0004_auto__del_field_book_created_date__add_field_post_contentmarkdown__chg.py", line 12, in forwards
db.delete_column('blog_book', 'created_date')
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/db/mysql.py", line 28, in _column_rm
return func(self, table_name, column_name, *args, **opts)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/db/mysql.py", line 217, in delete_column
super(DatabaseOperations, self).delete_column(table_name, name)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/db/generic.py", line 51, in _column_rm
return func(self, table, column, *args, **opts)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/db/generic.py", line 886, in delete_column
self.execute(self.delete_column_string % params, [])
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/south/db/generic.py", line 273, in execute
cursor.execute(sql, params)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/django/db/backends/util.py", line 40, in execute
return self.cursor.execute(sql, params)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 114, in execute
return self.cursor.execute(query, args)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 201, in execute
self.errorhandler(self, exc, value)
File "/home/ada/virtualenv/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.DatabaseError: (1091, "Can't DROP 'created_date'; check that column/key exists")
请告诉我为什么会收到此错误? 'created_date'没有任何意义??
答案 0 :(得分:3)
这是因为您正在尝试删除包含“created_date”列的内容,如果您查看它引用文件的错误,行号,甚至是有问题的代码段。
File "/home/ada/mainproject/blog/migrations/0004_auto__del_field_book_created_date__add_field_post_contentmarkdown__chg.py", line 12, in forwards db.delete_column('blog_book', 'created_date')
看起来你指的是错误的列名,因为你在变量'date_created'和'created_date'之间切换