Django - Errors Solving

I decide to write this article for the main purpose to collect solved problems of errors occuring during Django development project.

Error 1:

TypeError: Field ‘id’ expected a number but got datetime.datetime(2020, 3, 14, 8, 28, 56, 265918, tzinfo=<UTC>)

Question: What happened ?

I need to add the new fields showed in the picture below(user and cover_pic) in models.py file. The first one(user) I wanna make relationship between Post table and User table. Of course this field(user) requires ForeignKey, but it isn’t the point, and the last one is cover_pic field used to upload images to show a featured image for my blog post.

I added 2 fields; user and cover_pic in Post table

Problem: When running the command “python manage.py migrate” I suddenly got the error “TypeError: Field ‘id’ expected a number but got datetime.datetime…

the error I got

Then I decide to browse to migrations directory containing 3 files; 0001_initial.py, 0002_auto_2020.., and the last one __init__.py on the left hand side, just wanna make sure what happened in these fields. I Clicked on 0002_auto_2020.. file

migrations directory

Now I can see what happened. Focusing on the first parameter of each field, it stores datetime value. Indeed, it should not be datetime, it should be an integer value instead.

So I removed django.utils.timezone.now, then replace 1 to the default parameter → default=1.

run → python manage.py migrate

Job done!! No worries anymore, the problem is gone away. I can sleep well now ;)

If you like this article, do not forget to hit the clap to support my work, or you have any suggestions, do not hesitate to drop your comment to the comment section below.

See you next error !!

This article is written by: [Sonny STACKPYTHON]

--

--

--

Full Stack Python Developers

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What’s on Your Open Source Bucket List?

Introduction to GitHub Projects

Building a self-served ETL pipeline for third-party data ingestion

Why and how to use an ORM library (in a Node.js application)

Meeting the Future — Software Testing Trends For 2022

Compliance Test Suite for Dogelog Player

Code Signing iOS app extensions on Continuous Integration Server

Want to Dynamically Change Music in a Ruby CLI App?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
stackpython

stackpython

Full Stack Python Developers

More from Medium

How to create desktop notifications in Django?

Django!

Chapter 13 : Foreign Key

Store variables in a .env file (Django)