Django South初始迁移错误

时间:2011-04-16 15:45:06

标签: django migration django-south

我创建了一个新的Django 1.3项目和应用程序。我向南添加了settings.py并尚未运行syncdb。当我按照南方教程和文档执行以下命令时,我收到了如下所示的错误。

  • 有关导致问题的原因的任何想法? 更新:未正确安装South(请参阅答案)。
  • South 0.7.3与Django 1.3兼容吗? 更新:是。

执行的命令和南错误

$ 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
$ 

配置

我正在运行OS X 10.6.7。以下是pip 1.0virtualenv requirements.txt输出结果:

$ 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

1 个答案:

答案 0 :(得分:28)

Ken Cochrane's回答StackOverflow问题How Come My South Migrations Doesn't Work for Django持有密钥。

对于新的Django项目和应用程序,我必须执行以下步骤:

  1. INSTALLED_APPS中将South添加到settings.py,但不添加您的应用
  2. 运行syncdbDjangoSouth表添加到数据库中。 South修改了syncdb,因此INSTALLED_APPS中{{}}}非常重要。
  3. 将应用添加到INSTALLED_APPS
  4. 中的settings.py
  5. 为每个应用运行python manage.py schemamigration app_name --initial
  6. 运行python manage.py migrate app_name
  7. 阅读说明书 - 否,所有说明

    我很高兴开始使用South我跳过阅读South。我只是使用pip install south安装了installation documentation,然后将其添加到我的INSTALLED_APPS。那是我的错误。

    South州的Configuring Your Django Installation部分:

      

    添加南方后,您需要运行./manage.py syncdb以使installation documentation迁移跟踪表(South不对其自己的模型使用迁移,原因)。