2017-02-10 73 views
0

剛剛完成新建項目並創建超級用戶。當我編碼models.py並使用eclipse運行遷移時,它會拋出錯誤消息,並且我的Django管理員中沒有任何內容。運行Python時發生Mysql錯誤Django使用eclipse遷移

這是錯誤消息。

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/1.10/ref/databases/#mysql-sql-mode 
Operations to perform: 
    Apply all migrations: admin, auth, contenttypes, sessions 
Running migrations: 
    No migrations to apply. 
Finished "C:\Users\ds\workspace\board\manage.py migrate" execution. 

這是我的models.py

from __future__ import unicode_literals 
from django.db import models 
from unittest.util import _MAX_LENGTH 
from pip.cmdoptions import editable 
from django.template.defaultfilters import default 
from datetime import datetime 

# Create your models here. 


class User(models.Model): 
    id = models.CharField(_MAX_LENGTH=10) 
    password = models.CharField(_MAX_LENGTH=10) 
    join_date = models.DateTimeField(editable=False, default=datetime.now()) 


class todo(models.Model): 
    user = models.ForeignKey('id') 
    title = models.TextField 
    content = models.TextField 
    date = models.DateField(editable=False, default=datetime.now()) 
+0

酷的故事,兄弟。那裏有什麼問題嗎? https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – spencer7593

+0

你能否將settings.py中的數據庫部分添加到你的問題中? –

回答

1

這裏是文檔參考https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode

這裏是數據庫結構的例子來避免這種警告,未來的錯誤:

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.mysql', 
     'NAME': 'dbname', 
     'USER': 'dbuser', 
     'PASSWORD': 'dbpassword', 
     'HOST': 'localhost', 
     'PORT': '', 
     'OPTIONS': { 
      'init_command': "SET sql_mode='STRICT_TRANS_TABLES'", 
     }, 
    } 
}