- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我玩过 Django、python 和 MySQL;并在导入 django 时安装并使它们工作,通过 python 命令行导入 MySQLdb。
但是当我尝试在项目的根目录下执行 python manage.py syncdb 时,我得到了以下错误消息:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 231, in execute
self.validate()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/validation.py", line 103, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 415, in get_server_version
self.cursor().close()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 387, in _cursor
self.connection = Database.connect(**kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (13)")
可能的问题是什么?似乎是连接错误的东西?我是新手,感谢您的帮助:)
我附上了我的 settings.py 文件:
# Django settings for mysite project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '',
'USER': 'localhost',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
TIME_ZONE = 'America/Chicago'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
SECRET_KEY = 'wke73b4pm&s-g(ra*to+ykxe*3@0h=nrnt(v&3kf)fx=co*72@'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
WSGI_APPLICATION = 'mysite.wsgi.application'
TEMPLATE_DIRS = (
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
我可以使用命令行成功登录到 mysql 数据库:mysql -u 本地主机
在设置 HOST = "127.0.0.1"后,我收到更新的错误消息:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 60, in handle_noargs
tables = connection.introspection.table_names()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/__init__.py", line 896, in table_names
return self.get_table_list(cursor)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/mysql/introspection.py", line 33, in get_table_list
cursor.execute("SHOW TABLES")
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/util.py", line 40, in execute
return self.cursor.execute(sql, params)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 114, in execute
return self.cursor.execute(query, args)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.DatabaseError: (1046, 'No database selected')
最佳答案
只需添加数据库名称和端口号..
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'Database_name',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '',
'PORT': '3306',
}
}
关于python manage.py syncdb 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12684357/
我想创建一个名为“database1.sqlite”的数据库的表,所以我运行命令: python manage.py syncdb 但是当我执行命令时,我收到以下错误: Unknown command
您好,我对 Django 还很陌生,刚刚学习了 Python。我正在努力将其设置好。所以现在道歉! 我安装了 django 和 python (windows 7)。到目前为止,教程中的所有内容(某种
我有一个具有以下结构模型的 Django 项目: my_model/ ├── __init__.py ├── models/ ├── __init__.py ├── my_model.
我有一个项目,结构如下: project/ __init__.py db/ models/ __init__.py article.py
有没有办法在不加载 fixture 的情况下运行 syncdb?xo 最佳答案 ./manage.py help syncdb 建议如下: ./manage.py syncdb --no-initia
我试图让我的应用程序在 syncdb 上运行一些自定义 SQL,官方方法是将一些 INSERT 语句放入/sql/.sql 现在,当我运行“manage.py sqlall”时,我想要运行的所有 SQ
我正在新的开发环境中部署一个项目。 当我使用 South 时,我做了: $ python manage.py syncdb --all $ python manage.py migrate --fak
这次我想不是我愚蠢,而是真正的冲突。我有以下代码(简化): from django.db import models class Alpha(models.Model): relation =
是否可以让 manage.py syncdb 命令仅将自定义权限同步到 auth_permission table ?我不想为应用模型安装默认的三个权限,即 foo.add_bar , foo.cha
我在 PostgreSql 中有一个名为“tests”的数据库。我想编写 sh 脚本以将其与 django 同步,运行测试然后删除所有表。谁能提出合适的解决方案?一些脚本: DJANGO_DATABA
我是 python 和 Django 的新手,自从我们的编码员离开海外后,我实际上被派去为我的公司完成一些编码。 当我运行 python manage.py syncdb 时,我收到以下错误 psyc
我正在运行 syncdb。 Django 找到一个内容类型,我已经删除了相应的表: The following content types are stale and need to be delet
我添加了新模型并推送到我们的登台服务器,运行 syncdb 来创建它们的表,然后它就锁定了。就“创建表 photosusertag”而言,postgres 输出显示创建“photos_photouse
我有一些抛出的代码导致 syncdb 抛出错误(因为它试图在创建表之前访问模型)。 有没有办法让代码不在 syncdb 上运行?像这样的东西: if not syncdb: run_some_
我在基于 django 的应用程序中使用 Neo4Django,并尝试同时使用两个数据库:Neo4j 和 PostGIS。因此,我按照文档( http://neo4django.readthedocs
我的 models.py 中有这个: class AuditableTable(models.Model): class Meta: abstract = True
以前可以,现在不行了。 python manage.py syncdb 不再为我的应用创建表格。 来自 settings.py: INSTALLED_APPS = ( 'django.cont
我向现有模型添加了一个多对多字段,并期望 syncdb 创建一个新表,但那里什么也没有。这是模型的样子: class Author(models.Model): first_name = mo
我最近更新了我的模型,向它添加了一个 BooleanField,但是当我执行 python manage.py syncdb 时,它不会将新字段添加到模型的数据库中。我该如何解决这个问题? 最佳答案
我想了解 ./manage.py syncdb --all 究竟做了什么?我最近遇到了一个数据库问题,我可以通过运行此命令来修复它,但我不确定它在幕后做了什么。我知道 syncdb 为未随南方迁移的已
我是一名优秀的程序员,十分优秀!