尝试各种迁移后,即时通讯仍然收到此错误 我只会在尝试保存新对象时收到此错误
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py", line 741, in save
force_update=force_update, update_fields=update_fields)
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py", line 779, in save_base
force_update, using, update_fields,
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py", line 870, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py", line 908, in _do_insert
using=using, raw=raw)
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py", line 1186, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 1332, in execute_sql
cursor.execute(sql, params)
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 99, in execute
return super().execute(sql, params)
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: desporto_noticia
模型
import datetime
from django.db import models
from django.utils import timezone
class Noticia(models.Model):
noticia_texto = models.TextField()
noticia_imagem_path = models.CharField(max_length=100)
noticia_titulo = models.CharField(max_length=100, default='Default')
pub_data = models.DateTimeField('data de publicacao')
noticia_tema = models.CharField(max_length=100)
def __str__(self):
return self.noticia_texto
class Comentario(models.Model):
noticia = models.ForeignKey(Noticia, on_delete=models.CASCADE)
comentario_texto = models.CharField(max_length=300)
def __str__(self):
return self.comentario_texto
在我的数据库软件上找到这是唯一不存在的表,另一个模型有一个表 尝试了所有迁移,例如:
python manage.py makemigrations desporto
python manage.py sqlmigrate desporto 0001
python manage.py migrate
python manage.py migrate --run-syncdb
答案 0 :(得分:0)
您对Noticia模型的迁移已记录在django迁移表中,但已从数据库中删除。如果不是正式产品,则可以对数据库进行dorp处理,然后使用新的数据库架构重新运行迁移。如果您不想删除数据库,则可以从迁移表中删除迁移条目,然后重新运行migration命令。
通知:请不要在生产数据库中进行实验。