Django模型数据库

Djngo1.10.2下面使用 mysql-connector(2.1.4)连接的数据库python

安装mysql-connector:mysql

pip isntall mysql-connector

在Django中创建工程 ,在工程的models.py下建表,而后同步数据库sql

python manage.py makemigrations
python manage.py migrate

同步数据库时的一个库的bug解决方法,在替换路径数据库

/usr/local/lib/python3.5/dist-packages/mysql/connector/django/operations.py中的bulk_insert_sql函数:django

def bulk_insert_sql(self, fields, placeholder_rows):         
    """
    Format the SQL for bulk insert
    """
    placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
    values_sql = ", ".join("(%s)" % sql for sql in placeholder_rows_sql)
    return "VALUES " + values_sql

穿件admin管理帐号:bash

python manage.py createsuperuser

改密码:函数

>>> from django.contrib.auth.models import User

>>> u = User.objects.get(username__exact='john')
>>> u.set_password('new password')
>>> u.save()
相关文章
相关标签/搜索