Enter CMD as an administrator
net start MySQL
Mysql-u root-p
No password direct Enter, enter MySQL can create a database,
such as exiting MySQL execution \q: command
Create database Remember to specify the encoding CREATE database orm_1128 character set UTF8; ORM_1128 is the database name
Modify the character set of the database Mysql>use mydb
Mysql>alter database mydb character set UTF8;
If an error is
1045 ('root' @'localhost' (using Password:yes)
is because after the mysql5.6 version, you need to enter a password,
Set a new password, 123, the next time you log in, you will enter the password 123,
MySQL forroot= password ('123'1 Warning (0.29 sec)
=====
View the database and see the tables you have created
Mysql>show databases;+--------------------+|Database|+--------------------+| Information_schema|| Bookmanage1|| Bookmanage2|| Db1|| DB2 || gu_orm | | myorm || MySQL | | performance_schema || S5orm || school || SYS | +--------------------+12 rows in set (0.06 sec)
Select the encoded database that you want to modify, and then execute the \s; command to see the table's database encoding and other information, to modify
Mysql>UseGu_orm;DatabaseChangedmysql>\s--------------MySQL Ver14.14 Distrib5.7.18,ForWin64 (x86_64) Connection ID:70CurrentDatabase: Gu_ormCurrentUser:root@localhostSsl:NotInchUseUsing delimiter:; Server version:5.7.18MySQL Community Server (GPL) Protocol version:10Connection:localhost via TCP/Ipserver characterset:latin1db characterset:latin1client characterset: GBK--------------------------------------------------------------Conn. CharacterSet: GBK-----------------------------------------------------------------------TCP Port:3306Uptime:Hours39Min56Secthreads:4 Questions:860 Slow Queries: 0 Opens: 365 Flush tables: 1 Open tables: Queries per second avg: 0. 016--------------mysql> set character_set_client=UTF8;------Modify the encoding query OK, 0 rows affected (0.05 sec)
If an error occurs after creating the table---
File "C:\Python36\lib\site-packages\django\db\backends\mysql\base.py", line A, in <module>
' Did you install mysqlclient or Mysql-python? '% E
Django.core.exceptions.ImproperlyConfigured:Error loading mysqldb module:no module named ' MyS
Qldb '.
Did you install Mysqlclient or Mysql-python?
C:\users\lenovo\pycharmprojects\gu_orm_11month>
No mysqldb (drive)???
In the previous version of Python2 is MYSQLDB support, to Python3 after the use of Pymsql,
You only need to adjust the import pymsql in the __init__.py file under the project.
Write on Pymysql.install_as-mysqldb (), just do it.
When creating a one-to-many table, remember to put the main table, a table in front of many tables, or generate a database error
Execute Python manage.py makemigrations
Python manage.py Migrate
After creating the database, you can see the database in cmd,
Use database name, enter database, \s command to view database information
Show tables; View table
Mysql> UseGu_ormDatabaseChangedmysql>ShowTable - ; ERROR1064(42000): You had an errorinchyour SQL syntax;CheckThe manual that corresponds toYour MySQL server version forThe RightSyntax to UseNear"'At line1MySQL>show tables;+----------------------------+|Tables_in_gu_orm|+----------------------------+|Auth_group||Auth_group_permissions||Auth_permission||Auth_User||Auth_user_groups||Auth_user_user_permissions||Django_admin_log||Django_content_type||Django_migrations||Django_session||Gu_orm_book||Gu_orm_publish|+----------------------------+ ARowsinch Set(0.00Sec
See here, it means that it's connected to the database, just like the table in Pycharm.
But every time in the cmd check data inconvenient, you can set in the Pycharm,
The table will appear, apply, OK, you can use the
A one-to-many table, first insert data to a table, and then in a number of tables to insert data, because the first time to insert data into a number of tables, there is a foreign key, the need for data, so first a table to insert data,
On the coding problem of database
The table name of the show create table database; View the encoding of the table
ALTER TABLE database name charset UTF8; Modify table encoding
-------
Errors that occur when the database is re-migrated,
C:\Users\lenovo\PycharmProjects\gu_ORM_11month>python manage.py makemigrationsno changes detected
Remember to add the app name to the back
C:\Users\lenovo\PycharmProjects\gu_ORM_11month>for'gu_orm' : gu_orm\migrations\0001_initial.py -Create Model Book -Create model Publish -Add field PU
to book
In the execution of Python manage.py migrate
C:\Users\lenovo\PycharmProjects\gu_ORM_11month>python manage.py migrateoperations toperform:apply Allmigrations:admin, auth, ContentTypes, Gu_orm, sessionsrunning migrations:applying contenttypes.0001_initial ... OK Applying auth.0001_initial ... OK Applying admin.0001_initial ... OK Applying Admin.0002_logentry_remove_auto_add ... OK Applying Contenttypes.0002_remove_content_type_name ... OK Applying auth.0002_alter_permission_name_max_length ... OK Applying auth.0003_alter_user_email_max_length ... OK Applying auth.0004_alter_user_username_opts ... OK Applying Auth.0005_alter_user_last_login_null ... OK Applying auth.0006_require_contenttypes_0002 ... OK Applying auth.0007_alter_validators_add_error_messages ... OK Applying auth.0008_alter_user_username_max_length ... OK Applying gu_orm.0001_initial ... OK Applying sessions.0001_initial ... OK
MySQL coding in Django projects, database migration issues