2013-05-14 185 views
1

让我进一步阐明我想要做的事情。我一直在我的机器上开发我的Django项目。我也将代码检查到一个存储库中。目前我是唯一的开发者,但其他开发者将加入。他们将从存储库检出代码并在其机器上运行它。为了模拟这种情况,我检查了我的代码到另一个目录并创建了一个新的数据库。我更新了checkout的settings.py以使用新的数据库。当我执行syncdb重新创建表,我得到这个错误:Django:重新创建表格

User Host  Type Privileges  Grant Action 
root localhost global ALL PRIVILEGES Yes  Edit Privileges 

,并从settings.py:

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 
     'NAME': 'testproj',    # Or path to database file if using sqlite3. 
     # The following settings are not used with sqlite3: 
     'USER': 'root', 
     'PASSWORD': '****', 
     'HOST': '127.0.0.1',   # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 
     'PORT': '',      # Set to empty string for default. 
    } 
} 

这里是

$ python -i manage.py syncdb 
DatabaseError: (1146, "Table 'testproj.auth_user' doesn't exist") 
Traceback (most recent call last): 
    File "manage.py", line 13, in <module> 
    execute_from_command_line(sys.argv) 
    File "c:\Users\jpp\Documents\.virtualenvs\django-test\lib\site-packages\dja 
ngo\core\management\__init__.py", line 453, in execute_from_command_line 
    utility.execute() 
    File "c:\Users\jpp\Documents\.virtualenvs\django-test\lib\site-packages\dja 
ngo\core\management\__init__.py", line 392, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "c:\Users\jpp\Documents\.virtualenvs\django-test\lib\site-packages\dja 
ngo\core\management\base.py", line 230, in run_from_argv 
    sys.exit(1) 
SystemExit: 1 

这里从phymyadmin是我的数据库设置INSTALLED_APPS:

INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    # Uncomment the next line to enable the admin: 
    # 'django.contrib.admin', 
    # Uncomment the next line to enable admin documentation: 
    # 'django.contrib.admindocs', 
    'helloworld', 
) 

因此,我怀疑另一个开发者有这个相同的问题。这是以前必须解决的情况,但我还没有能够将Google的正确词汇放在一起。

+0

请显示完整的回溯,也是您的数据库设置(不要忘记在显示给我们之前更改数据库的密码) – 2013-05-14 03:52:27

+0

保持HOST也为空。还请显示setup.py的installed_apps – 2013-05-14 06:39:53

+0

好的,当我这样做时,出现此错误:'OperationalError:(2003,“无法连接到'localhost'(10061)”)上的MySQL服务器''。但是,我一直使用HOST作为127.0.0.1成功用于我的其他项目;本地主机不适合我。 – user2233706 2013-05-14 12:03:59

回答

0

我发现了这个问题。

在我所创造的应用,HelloWorld的,我曾在__init__.py如下:

from django.contrib.auth.models import User 

if User.objects.filter(username="hello").count() == 0: 
    user = User.objects.create_user(username='hello', password='hellotest') 
    user.save() 

当我注释掉整个if语句,跑执行syncdb,所有的表被重新创建。我猜在创建所有自己的表之前,auth_user,auth_group等。Django可以完成应用程序所需的任何工作。我不确定这是否是由于python进程包或Django中的错误/限制造成的。

0

你并不需要创建测试表,Django将做自动

Test db documentation

如果您愿意,您可以使用单独的数据库进行测试,只需将其添加到您的settings file即可。确保数据库已创建,但Django自己创建表。

+0

这不是一个“测试”数据库,而是我创建的另一个数据库,用于测试当其他人检出我的代码时,他们在运行项目时为他们准备好的表格。我没有另外一台机器来测试这个,所以为了模拟这个场景,我只是将我的代码签出到另一个目录并更改了数据库的名称。我创建的数据库是空的,它不是以“test”开始的。我猜出了偏执狂,当我发布这个时,我改变了名字。 – user2233706 2013-05-14 12:00:39