Error-'You are trying to add a non-nullable field 'author' to post without a default'

Please Help. I am working on Django Series Tutorial by Corey Schafer. @KenWhitesell … Yes I know you say I should work on more recent tutorials.
The truth is aside from the LearnDjango tutorials which helped me to really grasp and understand Django, the tutorial series by CoreyMS and Real Python have helped boost my understanding of Django.
I wish I had the book Django for Beginners by William Vincent. That is my wish list and like a kid I continue to wish and ask the tooth fairy that I get the book for my 74th birthday coming up February 13, 2025.

Anyway this tutorial by Corey Schafer uses Django 2.1. So using what I learned from following the tutorials on LearnDjango I created a virtual environment and installed Django as I was taught like so

python -m pip install django~=2.1

With pip freeze I saw that I had django 2.2.28 installed. Right now on the Python Django tutorial series by Corey M Schafer
I am at Part 5 of the tutorials(Database and Migrations). I am coding with the Python Interpreter Console. Everything goes fine until I run the following command.

>>> user = User.objects.get(id=1)
>>> user
<User: zackamata>
>>> Post.objects.all()
Traceback (most recent call last):
  File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\Corey Schafer\djangoProject\venv\Lib\site-pack
ages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\Corey Schafer\djangoProject\venv\Lib\site-pack
ages\django\db\backends\sqlite3\base.py", line 383, in execute
    return Database.Cursor.execute(self, query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such column: blog_post.author_id

I then tried to makemigrations and I get the following in my command prompt

(venv) C:\Users\ZACKAMATA\Documents\Learn Python\Django\Corey Schafer\djangoProject\djangoProject2>pyth
ject\djangoProject2>python manage.py makemigrations                                                                            You are trying to add a non-nullable field 'author' to post without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:                                                                                    1) Provide a one-off default now (will be set on
 all existing rows with a null value for this column)  2) Quit, and let me add a default in models.py
Select an option:

This is new to me so I would like to ask how do I add the default. Thanks for your patience and your understanding

As the quickest possible answer, you could try entering 1 to add a default value and then entering 1 as the default value.

If that doesn’t work, then you could look at your existing data to see what data is currently in those tables to get a valid author_id to use as the default.

Or, if you’re using sqlite, you could delete the database file, run migrate, then run makemigrations and migrate.

Note: Regarding your comment:

Actually it’s not. It’s close - close enough to be able to cause confusion.
It is giving you an understanding of Django as it was 6 years ago - ignoring everything new that has been added since then, and teaching you some things that no longer exist.

1 Like

Thanks @KenWhitesell. I really appreciate your advice. While waiting for the community to reply I checked online and read somewhere about entering an attribute of null=True and blank=True. I will go back and read over. I am a slow learner. So i tend to read things over and over again. But I must say it is fun and really satisfying to see things come up on my screen after typing some code. Really cool. You guys are my celebrities. Thank you to all of you - @KenWhitesell @philgyford @qvisty the guys at Real Python and FreeCodeCamp @wsvincent.

Thank you. I didn’t do much, but encourage :slightly_smiling_face:

H1 @KenWhitesell I followed your suggestion and typed in 2. I went to my blog/models.py file and added

blank=True, null=True

and my code is now working. Thanks so much. I have just seen that LearnDjango has a Blog tutorial. I aim to work on that also. I am an actor and film producer. I am learning Django so I can build something like a Members Website or Nollywood directory(Nollywood is the Nigerian Film industry). The website will have categories like Actor, Actress, Scriptwriter, Cameraman, Costume Designer, Makeup , Technical Director, Producer , Director etc. (ListView)On clicking on a category it will take you to a page where all registered members in the category. Then clicking on each image will take you to a page with full details of each person (DetailView). I think I can do it. Still got a long way to go. Thanks