Django.fun

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 manage.py 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\manage.py", line 22, in <module>
    main()
  File "D:\Rushikesh\Code\car_rent\quickrents\manage.py", line 18, in main 
    execute_from_command_line(sys.argv)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\base.py", line 414, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\base.py", line 98, in wrapped
    res = handle_func(*args, **kwargs)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\core\management\commands\migrate.py", line 290, in handle
    post_migrate_state = executor.migrate(
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\migrations\executor.py", line 131, in migrate
    state = self._migrate_all_forwards(
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\migrations\executor.py", line 163, in _migrate_all_forwards
    state = self.apply_migration(
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\migrations\executor.py", line 248, in apply_migration
    state = migration.apply(state, schema_editor)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\migrations\migration.py", line 131, in apply
    operation.database_forwards(
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\migrations\operations\fields.py", line 108, in database_forwards
    schema_editor.add_field(
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\backends\sqlite3\schema.py", 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\schema.py", line 230, in _remake_table
    self.effective_default(create_field)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\db\backends\base\schema.py", 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\__init__.py", 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\__init__.py", 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\__init__.py", 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\__init__.py", 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\__init__.py", line 1485, in to_python
    parsed = parse_datetime(value)
  File "D:\Rushikesh\Code\car_rent\ecp\lib\site-packages\django\utils\dateparse.py", 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 models.py file.

from django.db import models
from django.contrib.auth.models import User
from django.core.validators import MaxValueValidator, MinValueValidator
STATE_CHOICE = (
    ('Maharashtra','Maharashtra'),
    ('Rajasthan','Rajasthan'),
    ('Delhi','Delhi'),
    ('Tamil Nadu','Tamil Nadu'),
    ('Madhya Pradesh','Madhya Pradesh'),
    ('Gujrat','Gujrat'),
)
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(self.id)

CATEGORY_CHOICES = (
    ('H','HATCHBACK'),
    ('S','SEDAN'),
    ('SUV','SUV'),
    ('MUV','MUV'),
)

class Car(models.Model):
    title = models.CharField(max_length=100)
    renting_price = models.FloatField()
    description = models.TextField()
    mileage=models.CharField(max_length=2)
    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(self.id)

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(self.id)
    
STATUS_CHOICES = (
    ('Accepted','Accepted'),
    ('On The Way','On The Way'),
    ('Delivered','Delivered'),
    ('Cancel','Cancel'),
)

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(self.id)

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 manage.py migrate app_name zero

now delete all migrations files

Finally, recreate your new migration and apply it.

python manage.py makemigrations
python manage.py migrate

Tutorials

Современный 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 →