Problems encountered and solutions

Problems encountered

When using the django database connection error, suggesting that the database already exists

django default is actively creating a database of models based on the contents of the file, if you want to connect to a local database already exists, you can use

python ../manage.py inspectdb > models.py (需要先进入相关app文件夹内执行此命令,使用app.models.py这种方式,但是失败了)
根据已存在数据库生成orm类,写入models文件中,然后执行makemigrations,在执行migrate命令的时候需要在后面添加 
--fake-initial 参数

$ Python manage.py makemigrations
$ python manage.py migrate --fake-initial

So the error will not, and will connect to the data table with the same name.

django : 'str' object has no attribute 'tzinfo'报错

When used in the field is created using mysql datetime type created, but actual use is set to an initial value 0 is automatically filled 0000-00-00 00:00:00 this data format used in the orm  

DateTimeField inquiry will complain, and some teach you add auto_now = True setting in the back, but this way it becomes time to modify the data automatically populated time, this has not comply with my request, the house can only change is to DateTimeField became the
CharField, now finally able to connect to your database and query the data.

Guess you like

Origin www.cnblogs.com/codenoob/p/11934435.html