Написал я такой код:
import datetime
from django.db import models
from django.utils import timezone
class Article(models.Model):
title = models.CharField('Название статьи', max_length=200)
text = models.TextField('Текст статьи', max_length=200)
pub = models.DateTimeField('Дата публикации', max_length=200)
def __str__(self):
return self.title
def publish(self):
return self.pub_date >= (timezone.now() - datetime.timedelta(days = 7))
class Comment(models.Model):
article = models.ForeignKey(Article, on_delete = models.CASCADE)
author = models.CharField('Имя автора', max_length=20)
text = models.CharField('Текст комментария', max_length=200)
def __str__(self):
return self.author
Сначала я захожу в Коммандную строку, и пишу:
1) python manage.py shell
2) from articles import Article, Comment
3) a = Article.objects.get(id = 1)
И после 3-ей этой строчки появляется ошибка:
spoilerЕсли что я делал миграции
Traceback (most recent call last):
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\sqlite3\base.py", line 477, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such column: articles_article.pub
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py", line 492, in get
num = len(clone)
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py", line 302, in __len__
self._fetch_all()
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py", line 1507, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py", line 57, in __iter__
results = compiler.execute_sql(
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\sql\compiler.py", line 1361, in execute_sql
cursor.execute(sql, params)
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 103, in execute
return super().execute(sql, params)
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\vue\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\sqlite3\base.py", line 477, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such column: articles_article.pub
>>>
Что делать?