0

我正在尝试构建我的第一个 Django 应用程序,但在最初的尝试中我无法让数据库正确同步。

我收到以下错误:

c:\mysite>manage.py syncdb
Traceback (most recent call last):
  File "C:\mysite\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 69, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
  File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 8, in <module>
    from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
  File "C:\Python27\lib\site-packages\django\core\management\sql.py", line 6, in <module>
    from django.db import models
  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 40, in <module>
    backend = load_backend(connection.settings_dict['ENGINE'])
  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "C:\Python27\lib\site-packages\django\db\utils.py", line 92, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "C:\Python27\lib\site-packages\django\db\utils.py", line 24, in load_backend
    return import_module('.base', backend_name)
  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
  File "C:\Python27\lib\site-packages\django\db\backends\postgresql_psycopg2\base.py", line 13, in <module>
    from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation
  File "C:\Python27\lib\site-packages\django\db\backends\postgresql_psycopg2\creation.py", line 1, in <module>
    import psycopg2.extensions
  File "C:\Python27\lib\site-packages\psycopg2\__init__.py", line 67, in <module>
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: DLL load failed: %1 is not a valid Win32 application.

我究竟做错了什么?

我已经安装了 Python 2.7、Postgres 9.1.3.1、psycopg 2.4.5(匹配 2.7 和 9.1.3)。

4

1 回答 1

2
ImportError: DLL load failed: %1 is not a valid Win32 application.

看起来你的机器和 Python/Postgres/psycopg 的架构不匹配。例如,如果您使用的是 32 位架构,但尝试安装 64 位代码。

检查这篇文章作为另一个有同样问题的人的例子。这似乎实际上可能是python版本问题。尝试使用您正在使用的其他版本安装 python。

于 2012-09-24T20:34:19.593 回答