各位大大好
小弟最近開始學django,跟著“it's django-用python迅速打造web應用”學習
但在建立modle跟資料庫同步時遇到錯誤訊息,而我用的環境是python2.7+django1.8
django.db.utils.OperationalError: table restaurants_food__new has no column named name
但我並沒有建立叫 restaurants_food__new 的 table 啊??
底下是我的models.py 內容
from django.db import models
# Create your models here.
class Restaurant(models.Model):
name = models.CharField(max_length=20)
phone_number = models.CharField(max_length=15)
address = models.CharField(max_length=50, blank=True)
class Food(models.Model):
name = models.Field(max_length=20)
price = models.DecimalField(max_digits=3,decimal_places=0)
comment = models.CharField(max_length=50, blank=True)
is_spicy = models.BooleanField(default=False)
restaurant = models.ForeignKey(Restaurant)
底下是完整錯誤訊息
-> python manage.py migrate restaurants 0001
Operations to perform:
Target specific migration: 0001_initial, from restaurants
Running migrations:
Rendering model states... DONE
Applying restaurants.0001_initial...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/migrate.py", line 221, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 110, in migrate
self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 148, in apply_migration
state = migration.apply(state, schema_editor)
File "/Library/Python/2.7/site-packages/django/db/migrations/migration.py", line 115, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Library/Python/2.7/site-packages/django/db/migrations/operations/fields.py", line 62, in database_forwards
field,
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/schema.py", line 179, in add_field
self._remake_table(model, create_fields=[field])
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/schema.py", line 147, in _remake_table
self.quote_name(model._meta.db_table),
File "/Library/Python/2.7/site-packages/django/db/backends/base/schema.py", line 111, in execute
cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py", line 318, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: table restaurants_food__new has no column named name
不曉得有沒有人也有遇到相同的問題
謝謝