2015-08-24 56 views
0

我创建了一个Django应用程序到Azure上的,所以我使用Python工具Visual Studio开发应用程序托管失败。我在根应用程序的models.py中创建了一个名为Client的模型。它实际上是一个模型表格,因为表格列都链接到我创建的表单中的字段。我使用MySQL,连接器是MySQLClient,因为我使用Python 3.4。我跑python manage.py syncdb和显示以下内容:Django的执行syncdb在应用auth.0001_initial

Operations to perform: 
Synchronize unmigrated apps: staticfiles, messages, VSpace 
Apply all migrations: auth, sessions, contenttypes, sites 
Synchronizing apps without migrations: 
Creating tables... 
    Creating table VSpace_Client 
    Running deferred SQL... 
Installing custom SQL... 
Running migrations: 
Rendering model states... DONE 
Applying auth.0001_initial...Traceback (most recent call last): 

这就是它失败的地方。我正在研究这个,我遇到了一些关于创建超级用户的事情。我尝试过,但输入凭据后失败。有谁知道为什么会发生这种情况?

编辑1:

回溯:

Traceback (most recent call last): 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\backends\utils.py", line 62, in execute 
    return self.cursor.execute(sql) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\backends\mysql\base.py", line 124, in execute 
    return self.cursor.execute(query, args) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\cursors.py", line 220, in execute 
    self.errorhandler(self, exc, value) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler 
    raise errorvalue 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\cursors.py", line 209, in execute 
    r = self._query(query) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\cursors.py", line 371, in _query 
    rowcount = self._do_query(q) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\cursors.py", line 335, in _do_query 
    db.query(q) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\connections.py", line 280, in query 
    _mysql.connection.query(self, query) 
_mysql_exceptions.OperationalError: (1050, "Table 'auth_permission' already exists") 

The above exception was the direct cause of the following exception: 

Traceback (most recent call last): 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\manage.py", line 17, in <module> 
    execute_from_command_line(sys.argv) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line 
    utility.execute() 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\core\management\__init__.py", line 330, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\core\management\base.py", line 393, in run_from_argv 
    self.execute(*args, **cmd_options) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\core\management\base.py", line 444, in execute 
    output = self.handle(*args, **options) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\core\management\commands\syncdb.py", line 25, in handle 
    call_command("migrate", **options) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\core\management\__init__.py", line 120, in call_command 
    return command.execute(*args, **defaults) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\core\management\base.py", line 444, in execute 
    output = self.handle(*args, **options) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\core\management\commands\migrate.py", line 221, in handle 
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\migrations\executor.py", line 110, in migrate 
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\migrations\executor.py", line 148, in apply_migration 
    state = migration.apply(state, schema_editor) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\migrations\migration.py", line 115, in apply 
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\migrations\operations\models.py", line 59, in database_forwards 
    schema_editor.create_model(model) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\backends\base\schema.py", line 286, in create_model 
    self.execute(sql, params or None) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\backends\base\schema.py", line 111, in execute 
    cursor.execute(sql, params) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\backends\utils.py", line 79, in execute 
    return super(CursorDebugWrapper, self).execute(sql, params) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\backends\utils.py", line 64, in execute 
    return self.cursor.execute(sql, params) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\utils.py", line 97, in __exit__ 
    six.reraise(dj_exc_type, dj_exc_value, traceback) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\utils\six.py", line 658, in reraise 
    raise value.with_traceback(tb) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\backends\utils.py", line 62, in execute 
    return self.cursor.execute(sql) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\django\db\backends\mysql\base.py", line 124, in execute 
    return self.cursor.execute(query, args) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\cursors.py", line 220, in execute 
    self.errorhandler(self, exc, value) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler 
    raise errorvalue 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\cursors.py", line 209, in execute 
    r = self._query(query) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\cursors.py", line 371, in _query 
    rowcount = self._do_query(q) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\cursors.py", line 335, in _do_query 
    db.query(q) 
    File "C:\Users\Vinu\Google Drive\VVN Group\VSPace\VSpace Website\VSpace\VSpace\env\lib\site-packages\MySQLdb\connections.py", line 280, in query 
    _mysql.connection.query(self, query) 
django.db.utils.OperationalError: (1050, "Table 'auth_permission' already exists") 
The Python REPL process has exited 
+0

请添加Traceback –

+0

嗨马克。刚刚添加了回溯。 – Vinu

回答

1

首先,尝试运行python manage.py migrate代替syncdb。如果我没有记错,syncdb命令将被弃用,而有利于makemigrationsmigrate命令。试试看,事情会变得更好。

相关:您使用的是什么版本的Django的?

+0

刚刚尝试过,它工作。我正在使用Django V1.8.3。 – Vinu

+0

太棒了!很高兴的事情解决了。 – JwM

1
  1. 删除迁移文件夹中的所有文件。
  2. 运行:python manage.py makemigrations
  3. 运行:python manage.py migrate
  4. 运行:python manage.py createsuperuser

正如JWM说syncdb已被弃用,现在使用makemigrationsmigrate

+0

嗨4ndr3。我在哪里可以找到迁移文件夹? – Vinu

+0

我刚刚运行makemigrations和迁移命令,现在它工作正常。 – Vinu

1

auth_permissions表已经存在于您的数据库,但移民认为它没有。尝试伪造迁移以克服这一点。

./manage.py migrate auth --fake 
+0

刚跑完命令。我收到以下错误:django.db.utils.ProgrammingError:(1146,“Table'vspacedb.django_site'does not exist”)。我不确定为什么这张桌子是必要的。 – Vinu

+0

马克,请你能解释背后的逻辑 - fake。这看起来像一种调试技术。我是Django的新手,所以我不知道这一点。 – Vinu

+0

如果数据库已经具有该状态,则伪造是一种跳过迁移(不执行SQL)的方式。请参阅此处:https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-option---fake –

相关问题