##迁移数据库
(Django) [kiosk@asimov ~/PycharmProjects/DjangoDemo/music]$ python3 manage.py makemigrations
.......
问题:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
解决:安装mysql-client(我用的anconda环境pip装不了的我用conda就装了,conda不行的话只能源码装了)
(Django) [kiosk@asimov ~/PycharmProjects/DjangoDemo/music]$ conda install mysqlclient ##安装mysql-client
Collecting package metadata: done
Solving environment: done
## Package Plan ##
environment location: /home/kiosk/anaconda3/envs/Django
added / updated specs:
- mysqlclient
The following packages will be downloaded:
package | build
---------------------------|-----------------
certifi-2019.3.9 | py37_0 155 KB
mysql-connector-c-6.1.11 | h597af5e_0 4.4 MB
mysqlclient-1.3.14 | py37h7b6447c_0 86 KB
openssl-1.1.1c | h7b6447c_1 3.8 MB
------------------------------------------------------------
Total: 8.5 MB
The following NEW packages will be INSTALLED:
mysql-connector-c pkgs/main/linux-64::mysql-connector-c-6.1.11-h597af5e_0
mysqlclient pkgs/main/linux-64::mysqlclient-1.3.14-py37h7b6447c_0
The following packages will be UPDATED:
certifi 2018.11.29-py37_0 --> 2019.3.9-py37_0
openssl 1.1.1b-h7b6447c_1 --> 1.1.1c-h7b6447c_1
Proceed ([y]/n)? y
Downloading and Extracting Packages
mysqlclient-1.3.14 | 86 KB | ############################################
######################################################
certifi-2019.3.9 | 155 KB | #############################################################
####################################################### | 100%
mysql-connector-c-6. | 4.4 MB | ####################################
########################################################### | 100%
openssl-1.1.1c | 3.8 MB | ##########################################
######################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
##配置url地址信息
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('index.urls')),
#path('ranking.html', include('ranking.urls')),
#path('play/',include('play.urls')),
#path('comment/',include('comment.urls')),
#path('search/',include('search.urls')),
#path('user/',include('user.urls')),
]
当包含多个urls时其他的urls和views没写好的情况下,想创建数据库,就写好你写models这>个中的urls和views就可以了,不然其他的都要写好才能创建数据库(容易报错)
##数据库的迁移与创建
(Django) [kiosk@asimov ~/PycharmProjects/DjangoDemo/music]$ python3 manage.py makemigrations
Migrations for 'index':
index/migrations/0001_initial.py
- Create model Comment
- Create model Dynamic
- Create model Label
- Create model Song
- Add field song to dynamic
- Add field song to comment
(Django) [kiosk@asimov ~/PycharmProjects/DjangoDemo/music]$ python3 manage.py migrate
System check identified some issues:
WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-sql-mode
Operations to perform:
Apply all migrations: admin, auth, contenttypes, index, sessions
Running 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 admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
##查看数据库