Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Django模型中添加日期字段后迁移时出错_Python_Sql_Django - Fatal编程技术网

Python 在Django模型中添加日期字段后迁移时出错

Python 在Django模型中添加日期字段后迁移时出错,python,sql,django,Python,Sql,Django,这是我的Django模型,在这个模型中,我想在原有字段之外添加另一个字段 class Offerta(models.Model): #old pre-existent fields ... #the field I want to add data_rifiuto = models.DateField(null=True, blank=True) 当我运行'makemigrations myapp'时没有问题,但当我运行'migrate'命令时,控制台显示一些错

这是我的Django模型,在这个模型中,我想在原有字段之外添加另一个字段

class Offerta(models.Model):
    #old pre-existent fields
    ...
    #the field I want to add
    data_rifiuto = models.DateField(null=True, blank=True)
当我运行
'makemigrations myapp'
时没有问题,但当我运行
'migrate'
命令时,控制台显示一些
错误

    Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python3/dist-packages/django/db/backends/sqlite3/base.py", line 337, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.IntegrityError: NOT NULL constraint failed: myapp_offerta.data_rifiuto

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/pycharm-2017.2.3/helpers/pycharm/django_manage.py", line 43, in <module>
    run_module(manage_file, None, '__main__', True)
  File "/usr/lib/python3.5/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/santoryu/richiestaTesi/manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
但是我明确地说,
null=True

编辑 类迁移(migrations.Migration):


我通过删除一些迁移文件解决了这个问题。现在它开始工作了。我尝试重新运行makemigration和migrate,但没有遇到任何问题。我认为问题出在先前文件的依赖项上

您能否从
makemigrations
添加生成的迁移文件?您是否有任何未应用的迁移?您能否添加
/manage.py showmigrations
的输出?因此,删除问题或编写答案并接受它。
sqlite3.IntegrityError: NOT NULL constraint failed: myapp_offerta.data_rifiuto
    dependencies = [
    ('myapp', '0037_remove_offerta_data_rifiuto'),
    ]

    operations = [
    migrations.AddField(
        model_name='offerta',
        name='data_rifiuto',
        field=models.DateField(blank=True, null=True),
    ),
    ]