Django:Field' X'没有默认值

时间:2016-04-21 19:19:07

标签: python mysql django django-models

我桌子的models.py是:

class TestCaseGlobalMetricData(models.Model):
    testRunData = models.ForeignKey(TestRunData)
    testCase = models.CharField(max_length=200)
    cvmTotalFree = models.IntegerField(default=0)
    systemFree = models.IntegerField(default=0)
    sharedMemory = models.IntegerField(default=0)

使用此表的代码部分是

TestCaseGlobalMetricData(testRunData=testRunDataObj,
                    testCase=tokens['tc_name'],
                    timestamp=tokens['timestamp'],
                    cvmTotalFree=totalFree).save()

执行此行时,会看到以下错误,

File "/web/memmon/eink-memmon/projects/process.py", line 382, in process_cvm_usage
    cvmTotalFree=totalFree).save()

.....

Warning: Field 'sharedMemory' doesn't have a default value

我尝试使用python manage.py shell插入表格,但效果很好。

在mysql中看到的表的模式是

+-----------------+--------------+------+-----+---------+----------------+
| Field           | Type         | Null | Key | Default | Extra          |
+-----------------+--------------+------+-----+---------+----------------+
| id              | int(11)      | NO   | PRI | NULL    | auto_increment | 
| testRunData_id  | int(11)      | NO   | MUL | NULL    |                | 
| testCase        | varchar(200) | NO   |     | NULL    |                | 
| cvmTotalFree    | int(11)      | NO   |     | NULL    |                | 
| systemFree      | int(11)      | NO   |     | NULL    |                | 
| sharedMemory    | int(11)      | NO   |     | NULL    |                | 
+-----------------+--------------+------+-----+---------+----------------+

注意: 今天sharedMemory已添加字段models.py。我使用makemigrationsmigrate命令进行了正确的迁移。

0 个答案:

没有答案