Django South错误,初始迁移 [英] Django South error with initial migration
问题描述
settings.py
,还没有运行 syncdb
。当我根据南方教程和文档执行以下命令时,我收到以下错误: - 有什么问题导致的问题? 更新:未正确安装South(请参阅答案)。
- South 0.7.3是否与Django 1.3兼容?
执行的命令和南方错误
$ b $在$ / Users / matthew / development / quest-projects / qexpense-tracker / quexptrkr中创建迁移目录,b
$ python ./manage.py schemamigration qexpenses /../ quexptrkr / qexpenses / migrations'...
在'/Users/matthew/development/quest-projects/qexpense-tracker/quexptrkr/../quexptrkr/qexpenses/migrations'中创建__init__.py。 ..
+添加模型qexpenses.Buyer
+添加模型qexpenses.Vendor
+添加模型qexpenses.Department
+添加模型qexpenses.Project
+添加模型qexp .PurchaseType
+添加的模型qexpenses.PurchaseOrder
创建的0001_initial.py。您现在可以使用以下方式应用此迁移:./manage.py migrate qexpenses
(qexpense-tracker)matthew @ Matthew-Rankins-MacBook-Pro:〜/ development / quest-projects / qexpense-tracker / quexptrkr
$ python ./manage.py migrate
追溯(最近的最后一次调用):
文件./manage.py,第14行在< module>
execute_manager(settings)
文件/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/core/management/__init__.py,第438行,在execute_manager
utility.execute()
文件/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/core/management/__init__.py中,行379,执行
self.fetch_command(子命令).run_from_argv(self.argv)
文件/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/ django / core / management / base.py,第191行,在run_from_argv
self.execute(* args,** options .__ dict__)
文件/Users/matthew/.virtualenvs/qexpense-tracker /lib/python2.7/site-packages/django/core/management/base.py,行220,执行
output = self.handle(* args,** options)
文件 /Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/south/management/commands/migrate.py,第105行,处理
ignore_ghosts = ignore_ghosts,
网络连接le/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/south/migration/__init__.py,第171行,在migrate_app
applied = check_migration_histories(applied,delete_ghosts, ignore_ghosts)
文件/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/south/migration/__init__.py,第72行,check_migration_histories
for h在历史中:
文件/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/query.py,第107行,在_result_iter
self._fill_cache()
文件/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/query.py,第772行,位于_fill_cache中
self._result_cache.append(self._iter.next())
文件/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/ models / query.py,第273行,迭代器
在compile.results_iter()中的行:
文件/Users/matthew/.virtualenvs/qexpense-tracker/l ib / python2.7 / site-packages / django / db / models / sql / compiler.py,第680行,result_iter
for self.execute_sql(MULTI)中的行:
文件/ Users /matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/sql/compiler.py,第735行,在execute_sql
cursor.execute(sql,params)
文件/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/backends/util.py,第34行,执行
return self .cursor.execute(sql,params)
文件/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py,行234,执行
返回Database.Cursor.execute(self,query,params)
django.db.utils.DatabaseError:没有这样的表:south_migrationhistory
(qexpense-tracker)matthew @ Matthew-Rankins-MacBook-Pro:〜/ development / quest-projects / qexpense-tracker / quexptrkr
$
配置
我正在运行OS X 10.6.7。以下是我的 pip 1.0 requirements.txt的输出。 virtualenv.org/en/latest/\"> virtualenv :
$ cat requirements.txt
Django == 1.3
South == 0.7.3
distribute == 0.6.15
virtualenv == 1.6
virtualenvwrapper == 2.6.3
wsgiref == 0.1。 2
Ken Cochrane的对StackOverflow问题的回答如何来我的南方迁移不适用于Django 的关键。
对于一个新的Django项目和应用程序,我必须执行以下步骤:
- 添加南到
INSTALLED_APPS
在settings.py
中,但是做n添加您的应用程序 - 运行
syncdb
添加 Django 和 South 表到数据库。 South 修改syncdb
,所以重要的是要有<您的INSTALLED_APPS
中的href =http://south.aeracode.org/ =nofollow noreferrer>南。 - 将应用程序添加到
INSTALLED_APPS
中settings.py
- 为每个应用程序运行
python manage.py schemamigration app_name --initial
- 运行
python manage.py migrate app_name
阅读说明 - 否,所有说明
我很高兴开始使用 South ,我跳过阅读安装文档。我使用 pip install south
安装 South ,然后刚添加到我的 INSTALLED_APPS
。这是我的错误。
配置Django安装部分的安装文档状态:
一旦添加了South,您需要运行
./ manage.py syncdb
使 South 迁移跟踪表( South 不会为自己的模型使用迁移,由于种种原因)。
I have a new Django 1.3 project and app that I've created. I added south to my settings.py
and have not yet run syncdb
. When I execute the following commands per the South tutorial and documentation, I received the error shown below.
- Any thoughts on what's causing the problem? Update: Not properly installing South (see answer).
- Is South 0.7.3 compatible with Django 1.3? Update: Yes.
Commands Executed and South Error
$ python ./manage.py schemamigration qexpenses --initial
Creating migrations directory at '/Users/matthew/development/quest-projects/qexpense-tracker/quexptrkr/../quexptrkr/qexpenses/migrations'...
Creating __init__.py in '/Users/matthew/development/quest-projects/qexpense-tracker/quexptrkr/../quexptrkr/qexpenses/migrations'...
+ Added model qexpenses.Buyer
+ Added model qexpenses.Vendor
+ Added model qexpenses.Department
+ Added model qexpenses.Project
+ Added model qexpenses.PurchaseType
+ Added model qexpenses.PurchaseOrder
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate qexpenses
(qexpense-tracker)matthew@Matthew-Rankins-MacBook-Pro:~/development/quest-projects/qexpense-tracker/quexptrkr
$ python ./manage.py migrate
Traceback (most recent call last):
File "./manage.py", line 14, in <module>
execute_manager(settings)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/south/management/commands/migrate.py", line 105, in handle
ignore_ghosts = ignore_ghosts,
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/south/migration/__init__.py", line 171, in migrate_app
applied = check_migration_histories(applied, delete_ghosts, ignore_ghosts)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/south/migration/__init__.py", line 72, in check_migration_histories
for h in histories:
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/query.py", line 107, in _result_iter
self._fill_cache()
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/query.py", line 772, in _fill_cache
self._result_cache.append(self._iter.next())
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/query.py", line 273, in iterator
for row in compiler.results_iter():
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Users/matthew/.virtualenvs/qexpense-tracker/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 234, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: south_migrationhistory
(qexpense-tracker)matthew@Matthew-Rankins-MacBook-Pro:~/development/quest-projects/qexpense-tracker/quexptrkr
$
Configuration
I'm running OS X 10.6.7. Below is the output of pip 1.0 requirements.txt for my virtualenv:
$ cat requirements.txt
Django==1.3
South==0.7.3
distribute==0.6.15
virtualenv==1.6
virtualenvwrapper==2.6.3
wsgiref==0.1.2
Ken Cochrane's answer to the StackOverflow question How Come My South Migrations Doesn't Work for Django held the key.
For a new Django project and app, I had to perform the following steps:
- Add South to
INSTALLED_APPS
insettings.py
, but do not add your apps - Run
syncdb
to add the Django and South tables to the database. South modifiessyncdb
, so it's important to have South in yourINSTALLED_APPS
. - Add apps to
INSTALLED_APPS
insettings.py
- Run
python manage.py schemamigration app_name --initial
for each app - Run
python manage.py migrate app_name
Read the instructions—No, all of the instructions
I was so excited to start using South that I skipped reading the installation documentation. I simply installed South using pip install south
and then just added it to my INSTALLED_APPS
. That was my mistake.
The Configuring Your Django Installation section of the installation documentation states:
Once South is added in, you’ll need to run
./manage.py syncdb
to make the South migration-tracking tables (South doesn’t use migrations for its own models, for various reasons).
这篇关于Django South错误,初始迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!