我无法理解为什么我的sqlite数据库不能正常使用makemigrations命令。当我添加了一个名为userphoto的列并尝试进行迁移时,出现了错误信息"table categories_Category has no column named userphoto"。
我的python版本是3.4,django版本是1.7,只添加了userphoto这一列。
class Category(models.Model):
username = models.CharField(max_length=15)
realname = models.CharField(max_length=20)
tweets = models.CharField(max_length=1000)
tweettime = models.DateTimeField(max_length=30)
tweetidnum = models.CharField(max_length=30)
userphoto = models.CharField(max_length=100)
然后收到以下错误消息:
File "/Users/xxxxxxxxx/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: table categories_category has no column named userphoto
看起来这可能只是一个sqlite3的问题?如果我将其转移到我的Web主机服务器上,是否可以避免这种情况?
编辑:根据要求提供完整的跟踪信息
(tg)boo!:tg spencertachick$ python manage.py makemigrations
/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/fields/__init__.py:1282: RuntimeWarning: DateTimeField Category.tweettime received a naive datetime (2015-03-04 16:01:00) while time zone support is active.
RuntimeWarning)
Traceback (most recent call last):
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: table categories_category has no column named userphoto
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/Users/spencertachick/anaconda/envs/tg/tg/categories/models.py", line 54, in <module>
tweetidnum=user_timeline[x]['id_str'])
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/query.py", line 372, in create
obj.save(force_insert=True, using=self.db)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/base.py", line 589, in save
force_update=force_update, update_fields=update_fields)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/base.py", line 617, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/base.py", line 698, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/base.py", line 731, in _do_insert
using=using, raw=raw)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/query.py", line 921, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 920, in execute_sql
cursor.execute(sql, params)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: table categories_category has no column named userphoto
categories/migrations/
文件夹中有哪些文件?0001_initial.py
中有什么代码? - knbkFile "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute return Database.Cursor.execute(self, query, params) django.db.utils.OperationalError: no such table: categories_category
。 - stachick