[英]django.db.utils.OperationalError: (1046, 'No database selected')
Getting a strange error. 得到一个奇怪的错误。 I created a database in MySQL, set the database to use it.
我在MySQL中创建了一个数据库,设置数据库使用它。 Using the right settings in my Django settings.py.
在我的Django settings.py中使用正确的设置。 But still there's an error that no database has been selected.
但是仍然存在没有选择数据库的错误。
First I tried: 首先我试过:
python manage.py syncdb
Got this traceback: 得到了这个追溯:
django.db.utils.OperationalError: (1046, 'No database selected')
settings.py: settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_db',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
}
}
What have I missed? 我错过了什么?
Check to make sure your database my_db exists in your MySQL instance. 检查以确保您的数据库my_db存在于MySQL实例中。 Log into MySQL and run;
登录MySQL并运行;
show databases;
make sure my_db exists. 确保my_db存在。 If it does not, run
如果没有,请运行
create database my_db;
GRANT access privileges to the user mentioned in the file GRANT访问文件中提到的用户的权限
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
You need not grant all privileges. 您无需授予所有权限。 modify accordingly.
相应地修改。
Try with empty port - 尝试使用空端口 -
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_db',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.