I'm getting an datetime error while making an car renting django web application

I'm creating an car renting web based application using django. And I'm getting following error even though I have removed datetime attribute or function from my code

python migrate       
Operations to perform:
  Apply all migrations: admin, app, auth, contenttypes, sessions
Running migrations:
  Applying app.0006_cart_car_cart_quantity_cart_renting_date_and_more...Traceback (most recent call last):
  File "D:\Rushikesh\Code\car_rent\quickrents\", line 22, in <module>
  File "D:\Rushikesh\Code\car_rent\quickrents\", line 18, in main 
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\", line 446, in execute_from_command_line
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\", line 440, in execute
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\", line 414, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\", line 460, in execute
    output = self.handle(*args, **options)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\", line 98, in wrapped
    res = handle_func(*args, **kwargs)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\commands\", line 290, in handle
    post_migrate_state = executor.migrate(
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\migrations\", line 131, in migrate
    state = self._migrate_all_forwards(
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\migrations\", line 163, in _migrate_all_forwards
    state = self.apply_migration(
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\migrations\", line 248, in apply_migration
    state = migration.apply(state, schema_editor)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\migrations\", line 131, in apply
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\migrations\operations\", line 108, in database_forwards
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\backends\sqlite3\", line 381, in add_field
    self._remake_table(model, create_field=field)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\backends\sqlite3\", line 230, in _remake_table
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\backends\base\", line 410, in effective_default
    return field.get_db_prep_save(self._effective_default(field), self.connection)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\models\fields\", line 910, in get_db_prep_save
    return self.get_db_prep_value(value, connection=connection, prepared=False)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\models\fields\", line 1546, in get_db_prep_value
    value = self.get_prep_value(value)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\models\fields\", line 1524, in get_prep_value
    value = super().get_prep_value(value)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\models\fields\", line 1403, in get_prep_value
    return self.to_python(value)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\models\fields\", line 1485, in to_python
    parsed = parse_datetime(value)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\utils\", line 114, in parse_datetime
    return datetime.datetime.fromisoformat(value)
TypeError: fromisoformat: argument must be str

I tried using datetime function for making My_Orders page but got same error.

So I removed the datetime code to make it like before but then also getting same error.

Can't resolve this problem.

When I'm trying to run the code it is executing.

But warns to make 6 migrations as following.

Here is the image that shows 6 remaining migrations

But when I'm trying to make migrations the above error pops up.

Here is code from my file.

from django.db import models
from django.contrib.auth.models import User
from django.core.validators import MaxValueValidator, MinValueValidator
    ('Tamil Nadu','Tamil Nadu'),
    ('Madhya Pradesh','Madhya Pradesh'),
class Customer(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    name = models.CharField(max_length=200)
    locality = models.CharField(max_length=200)
    city = models.CharField(max_length=50)
    zipcode = models.IntegerField()
    state = models.CharField(choices=STATE_CHOICE, max_length=50)
    mobile = models.IntegerField()

    def __str__(self):
        return str(


class Car(models.Model):
    title = models.CharField(max_length=100)
    renting_price = models.FloatField()
    description = models.TextField()
    brand = models.CharField(max_length=50)
    category = models.CharField(choices=CATEGORY_CHOICES, max_length=3)
    car_image = models.ImageField(upload_to='carimg')

    def __str__(self):
        return str(

class My_Orders(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    car = models.ForeignKey(Car, on_delete=models.CASCADE)
    quantity = models.PositiveIntegerField(default=1)

    def __str__(self):
        return str(
    ('On The Way','On The Way'),

class OrderPlaced(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
    car = models.ForeignKey(Car, on_delete=models.CASCADE)
    quantity = models.PositiveIntegerField(default=1)
    status = models.CharField(max_length=50,choices=STATUS_CHOICES,default='Pending')

    def __str__(self):
        return str(

You appear to have a migration error about a field that no longer exists in your model. The easiest way to fix that is to purge all existing migrations and recreate a new one from scratch. You will loose all data, but since your project still is in development that approach should be possible.

You can do this with these commands:

python migrate app_name zero

now delete all migrations files

Finally, recreate your new migration and apply it.

python makemigrations
python migrate


Современный Python: начинаем проект с pyenv и poetry

Настройка проекта Python — виртуальные среды и управление пакетами

Использование requests в Python — тайм-ауты, повторы, хуки

Понимание декораторов в Python

ProcessPoolExecutor в Python: полное руководство

map() против submit() с ProcessPoolExecutor в Python

Понимание атрибутов, словарей и слотов в Python

Полное руководство по slice в Python

Выпуск Django 4.0

Безопасное развертывание приложения Django с помощью Gunicorn, Nginx и HTTPS

Автоматический повтор невыполненных задач Celery

Django REST Framework и Elasticsearch

Докеризация Django с помощью Postgres, Gunicorn и Nginx

Асинхронные задачи с Django и Celery

Релизы безопасности Django: 3.2.4, 3.1.12 и 2.2.24

Выпуски исправлений ошибок Django: 3.2.3, 3.1.11 и 2.2.23

Эффективное использование сериализаторов Django REST Framework

Выпуски безопасности Django: 3.2.2, 3.1.10 и 2.2.22

Выпущенные релизы безопасности Django: 3.2.1, 3.1.9 и 2.2.21

Обработка периодических задач в Django с помощью Celery и Docker

View all tutorials →