Python连接Mysql数据库报错,安装MySQLdb模块

Python-MySQLdb源码安装

如自动化脚本所示:

[plain] view plain copy
  1. cd $SRCDIR  
  2. apt-get install -y python-dev libmysqld-dev  
  3. wget http://nchc.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz  
  4. tar -zxvf MySQL-python-1.2.3.tar.gz  
  5. cd MySQL-python-1.2.3  
  6. sed -i -e "s/#mysql_config = \/usr\/local\/bin\/mysql_config/mysql_config=\/usr\/local\/bin\/mysql\/bin\/mysql_config/g" ./site.cfg  
  7. python setup.py build  
  8. python setup.py install  
  9. ln -s $INSTALLDIR/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18 

python manage.py syncdb

为数据库中每个应用建立一个数据库表。
然而如果你安装的Django Version >= 1.9,那么会出现如下问题:

gzxultra@gzxultraPC:~/django_try/mysite$ python manage.py syncdb
Unknown command: 'syncdb'
Type 'manage.py help' for usage.
gzxultra@gzxultraPC:~/django_try/mysite$ python manage.py syncdbpython manage.py syncdb
Unknown command: 'syncdbpython'
Type 'manage.py help' for usage.

在stackoverflow上找到原因和解决方法:
syncdb is deprecated because of the migration system.
Now you can log your changes using makemigrations. This transforms your model changes into python code to make them deployable to another databases.
After you created the migrations you have to apply them: migrate.
So instead of using syncdb you should use makemigrations and then migrate.

简言之:在Django 1.9及未来的版本种使用migrate代替syscdb.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值