错误地从我的模型中删除了id字段

时间:2017-11-23 06:46:06

标签: django python-3.x django-models

我不小心从模型中删除了id字段。现在我要撤消它。我收到完整性错误 - 数据类型不匹配错误。

python manage.py makemigrationspython manage.py migrate运行良好,没有任何问题。我也删除了模型并再次创建它。创建后,在迁移模型时创建的0001_initial.py文件包含默认的id列。但我仍然无法解决我的问题。

完整的错误跟踪如下:

        Internal Server Error: /drizzlelore/createEvents
    Traceback (most recent call last):
      File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\backe
    nds\utils.py", line 65, in execute
        return self.cursor.execute(sql, params)
      File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\backe
    nds\sqlite3\base.py", line 328, in execute
        return Database.Cursor.execute(self, query, params)
    sqlite3.IntegrityError: datatype mismatch

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

    ngo\dTraceback (most recent call last):
      File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\core\han
    dlers\exception.py", line 41, in inner
        response = get_response(request)
      File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\core\han
    dlers\base.py", line 187, in _get_response
        response = self.process_exception_by_middleware(e, request)
      File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\core\han
    dlers\base.py", line 185, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "C:\Users\eloixir\Desktop\mysite\mysite\home\views.py", line 54, in creat
    e_event
        event = form.save()
      File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\forms\mo
    dels.py", line 463, in save
        self.instance.save()
      File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\model
    s\base.py", line 807, in save
        force_update=force_update, update_fields=update_fields)
      File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\model
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\model
s\base.py", line 837, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, upda
te_fields)
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\model
s\base.py", line 923, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\model
s\base.py", line 962, in _do_insert
    using=using, raw=raw)
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\model
s\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\model
s\query.py", line 1076, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\model
s\sql\compiler.py", line 1107, in execute_sql
    cursor.execute(sql, params)
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\backe
nds\utils.py", line 80, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\backe
nds\utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\utils
.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\utils\si
x.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\backe
nds\utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "C:\Users\eloixir\Desktop\mysite\myvenv\lib\site-packages\django\db\backe
nds\sqlite3\base.py", line 328, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: datatype mismatch

修改

这是models.py文件。

from django.db import models
from django import forms
from django.forms import ModelForm
class createEvent(models.Model):
    FirstName = models.CharField(max_length=100)
    LastName = models.CharField(max_length=100)
    EventName = models.CharField(max_length=150)
    EventOrganizer = models.CharField(max_length=150)
    Location = models.CharField(max_length=200)
    Date = models.DateField()
    LastDateOfRegistration = models.DateField()
    EventDetails = models.TextField()

0 个答案:

没有答案