因此,我有一个正在运行的项目,它使用MAMP本地服务器上的MySQL数据库,但为了遵从性问题,我需要更改数据库名称。所以我改变了它的甲基苯丙胺和我在settings.py改变了它的波纹管看到:如何更改在MAMP上运行的Django项目数据库名称?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'prototipodb', # Or path to database file if using sqlite3.
'USER': 'palapa', # Not used with sqlite3.
'PASSWORD': 'palapa', # Not used with sqlite3.
'HOST': '/Applications/MAMP/tmp/mysql/mysql.sock', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
我认为,这些变化都将保持平稳运行,但我得到了我的服务器上出现以下错误:
Unhandled exception in thread started by > Traceback (most recent call last): File "/Users/palapa2/projects/prototipo_tesis/venv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run self.validate(display_num_errors=True) File "/Users/palapa2/projects/prototipo_tesis/venv/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate num_errors = get_validation_errors(s, app) File "/Users/palapa2/projects/prototipo_tesis/venv/lib/python2.7/site-packages/django/core/management/validation.py", line 103, in get_validation_errors connection.validation.validate_field(e, opts, f) File "/Users/palapa2/projects/prototipo_tesis/venv/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field db_version = self.connection.get_server_version() File "/Users/palapa2/projects/prototipo_tesis/venv/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 415, in get_server_version self.cursor().close() File "/Users/palapa2/projects/prototipo_tesis/venv/lib/python2.7/site-packages/django/db/backends/init.py", line 306, in cursor cursor = self.make_debug_cursor(self._cursor()) File "/Users/palapa2/projects/prototipo_tesis/venv/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 387, in _cursor self.connection = Database.connect(**kwargs) File "build/bdist.macosx-10.9-intel/egg/MySQLdb/init.py", line 81, in Connect File "build/bdist.macosx-10.9-intel/egg/MySQLdb/connections.py", line 193, in init _mysql_exceptions.OperationalError: (1049, "Unknown database 'prototipodb'")
如果你能帮助我解决这个问题,我将不胜感激。我一直在考虑的事情之一是运行syncbd
命令来重建连接,但如果有更好的解决方案,我会很乐意考虑它。
是否已将''NAME':'prototipodb','更改为正确的数据库名称,因为它看起来并不像您所做的那样。 –