简体   繁体   中英

Django no such table after migrations

After trying all sort of migration im still getting this error I only get this error when trying to save the new object

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

Models

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

Went on my database software to find this is the only table non-existence, the other model has a table tables Tried all migrates ex:

python manage.py makemigrations desporto
python manage.py sqlmigrate desporto 0001
python manage.py migrate
python manage.py migrate --run-syncdb

Your migrations for the Noticia model has been recorded in the Django migrations table but deleted from the database. If it is not in production you can drop the database and rerun the migrations with the fresh database schema. If you don't want to drop the database then you can delete the migration entry from the migrations table and rerun the migrate command.

Notice : Please don't experiment it with the production database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM