gpt4 book ai didi

python - Django 1.7 makemigrations 不工作 - 没有名为的列

转载 作者:行者123 更新时间:2023-11-28 22:45:07 25 4
gpt4 key购买 nike

我不明白为什么我的 makemigrations 不能与 sqlite 一起工作。当我添加列 userphoto 并进行迁移时,我收到一条错误消息“表类别_类别没有名为 userphoto 的列”

python 3.4,django 1.7,只添加了用户照片

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 问题?我可以通过转移到我的虚拟主机服务器来避免这种情况吗?

编辑:每个请求的完整回溯

(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/models.py 中的第 54 行:

tweetidnum=user_timeline[x]['id_str'])

这显然是以某种方式试图创建一个 Category 实例并在导入模块时保存它。这会阻止迁移运行,因为在迁移有机会运行之前会引发未捕获的异常。

如果你想知道确切的原因,你必须提供更多的代码,但那一行是罪魁祸首。我怀疑它是多行 create 语句的一部分。

关于python - Django 1.7 makemigrations 不工作 - 没有名为的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28860105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com