每当我运行python manage.py migrate
时,我都无法获得所需的表格。我得到的唯一表格是django_content_type
和django_migrations
。因此我无法登录管理页面或创建超级用户。我正在使用MySQL-connector-python-rf
,python 3.4和Django 1.9.8我已按照删除表的说明创建新数据库,问题仍然存在。
这是我在settings.py
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'usermie',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'testerdb',
'USER': 'root',
'PASSWORD': '',
}
}
之前我在使用django并在同一台计算机上处理项目,但现在我不知道发生了什么以及为什么我没有得到这些表。
以下是我运行python manage.py migrate
(mie) C:\Users\dane_\DjangoProjects\pagemie>python manage.py makemigrations
Migrations for 'usermie':
0001_initial.py:
- Create model Usermie
(mie) C:\Users\dane_\DjangoProjects\pagemie>python manage.py migrate
Operations to perform:
Apply all migrations: contenttypes, auth, sessions, admin, usermie
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial...Traceback (most recent call last):
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\django\base.py", line 177, in _execute_wrapper
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\cursor.py", line 515, in execute
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\connection.py", line 488, in cmd_query
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\connection.py", line 395, in _handle_result
mysql.connector.errors.ProgrammingError: 1050 (42S01): Table 'django_content_type' already exists
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\migrations\executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\migrations\executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\migrations\executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\migrations\migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\migrations\operations\models.py", line 59, in database_forwards
schema_editor.create_model(model)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\backends\base\schema.py", line 284, in create_model
self.execute(sql, params or None)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\backends\base\schema.py", line 110, in execute
cursor.execute(sql, params)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\backends\utils.py", line 62, in execute
return self.cursor.execute(sql)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\django\base.py", line 227, in execute
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\django\base.py", line 180, in _execute_wrapper
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\django\base.py", line 177, in _execute_wrapper
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\cursor.py", line 515, in execute
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\connection.py", line 488, in cmd_query
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\connection.py", line 395, in _handle_result
django.db.utils.ProgrammingError: Table 'django_content_type' already exists
答案 0 :(得分:1)
MySql不接受日期时间值中的时区信息,例如<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js">
</script>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller('startUpController', function($scope) {
$scope.funding = {
startingEstimate: 0
};
$scope.calculate = function () {
$scope.funding.needed = $scope.funding.startingEstimate * 10;
};
$scope.submitFN = function () {
window.alert('Go and find more customers.')
}
$scope.resetFN = function () {
$scope.funding.startingEstimate = 0;
}
});
</script>
</head>
<body>
<div ng-app='mainApp'>
<form ng-submit="submitFN()" ng-controller="startUpController">
Starting: <input type="text" ng-change="calculate()" ng-model="funding.startingEstimate"/>
Recommended: {{funding.needed}}
<button>Fund my startup!</button>
<button type="button" ng-click="resetFN()">Reset</button>
</form>
</div>
</body>
</html>
,问题是'2016-07-25 22:45:16.507552+00:00'
部分。默认情况下,Django应该使用天真的日期时间对象,如下所示:https://docs.djangoproject.com/en/1.9/topics/i18n/timezones/所以通常这不应该是一个问题,但似乎您的数据包含时区。
也许您可以在settings.py中检查USE_TZ是否为False,然后尝试再次运行迁移。
答案 1 :(得分:-1)
我应该拥有的所有表格现在都在这里。这就是我做的。我删除了在数据库中创建的所有表。我还从usermie
删除了INSTALLED_APPS
。之后我跑了python manage.py migrate
。我想知道将USE_TZ
更改为False
是否做了什么,因为我在数据库中多次删除了表,但没有成功。我还删除了MySQL-connector-python-rf
。
我仍然收到这些消息,但现在看来都很好:
(mie) C:\Users\dane_\DjangoProjects\pagemie>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying sessions.0001_initial... OK
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
emit_post_migrate_signal(self.verbosity, self.interactive, connection.alias)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\sql.py", line 50, in emit_post_migrate_signal
using=db)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\dispatch\dispatcher.py", line 192, in send
response = receiver(signal=self, sender=sender, **named)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\contrib\auth\management\__init__.py", line 126, in create_permissions
Permission.objects.using(using).bulk_create(perms)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\query.py", line 450, in bulk_create
self._batched_insert(objs_without_pk, fields, batch_size)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\query.py", line 1056, in _batched_insert
using=self.db)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\query.py", line 1039, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\sql\compiler.py", line 1059, in execute_sql
for sql, params in self.as_sql():
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\sql\compiler.py", line 1047, in as_sql
result.append(self.connection.ops.bulk_insert_sql(fields, placeholder_rows))
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\django\operations.py", line 223, in bulk_insert_sql
TypeError: can't multiply sequence by non-int of type 'tuple'