使用MySQL连接器与Django

使用MySQL连接器与Django

本文介绍了使用MySQL连接器与Django 1.8的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作系统:CentOS 6.4
python版本3.4
django版本1.8



我曾研究过django框架。然后,我要搬到存储部分。首先学习,默认数据库是sqlite。所以我在settings.py文件中修改了一些值。

  #DATABASES = {
#'default' {
#'ENGINE':'django.db.backends.sqlite3',
#'NAME':os.path.join(BASE_DIR,'db.sqlite3'),

#}
DATABASES = {
'default':{
'ENGINE':'mysql.connector.django',
'NAME':'dj_mysql'
'USER':'root',
'PASSWORD':'',
'HOST':'127.0.0.1',
'PORT':''
}
}

我键入python3 manage.my migrate,我得到了错误。



我如何克服这种情况。 TT;
我一整天都在努力。



解决方案

看起来你正在尝试使用MySQL连接器。 Django文档建议它。 建议2.1.3支持Django 1.8,但用户仍然在该错误报告和中报告问题2.1.3。 / p>

访问MySQL数据库Django。



它很容易安装,例如pip:

  pip install mysqlclient 

然后,您需要做的就是将数据库设置更改为

  DATABASES = {
'default':{
'ENGINE':'django.db.backends.mysql',
...


OS : CentOS 6.4python version 3.4django version 1.8

I had studies about django framework. Then, I going to move to storage part. At first of study, the default database is sqlite. So I was change some values in the settings.py file.

#DATABASES = {
#    'default': {
#        'ENGINE': 'django.db.backends.sqlite3',
#        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
#    }
#}
DATABASES = {
    'default' : {
        'ENGINE' : 'mysql.connector.django',
        'NAME' : 'dj_mysql',
        'USER' : 'root',
        'PASSWORD' : '',
        'HOST' : '127.0.0.1',
        'PORT' :''
   }
}

I typed "python3 manage.my migrate", and I got these errors.

How can I overcome this situation. TT;I'm struggling all day long.

解决方案

It looks like you're trying to use MySQL connector. The Django docs suggest that it doesn't always support the latest version of Django. This bug report suggests that 2.1.3 supports Django 1.8, but users were still reporting problems with 2.1.3 on that bug report and in this question.

The Django docs recommend that you use mysqlclient to access MySQL databases with Django.

It's easy to install, for example with pip:

pip install mysqlclient

Then all you need to do is change your databases setting to

DATABASES = {
    'default' : {
        'ENGINE' : 'django.db.backends.mysql',
        ...

这篇关于使用MySQL连接器与Django 1.8的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 02:02