Reputation: 35
Hi my code was running smoothly as i was following a tutorial but at a new step while adding new component in the model Order (processing, aprouved, refunbd_requested, refund_granted) the code crashed, the migrations operated but can't migrate i need help please.
my models.py
from django.conf import settings
from django.db import models
from django.shortcuts import reverse
from django_countries.fields import CountryField
class Order(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL,
on_delete= models.CASCADE)
items = models.ManyToManyField(OrderItem)
start_date = models.DateTimeField(auto_now_add=True)
ordered_date = models.DateTimeField()
ordered = models.BooleanField(default=False)
billing_address = models.ForeignKey('BillingAddress',
on_delete= models.SET_NULL, blank=True, null=True)
payment = models.ForeignKey('Payment',
on_delete= models.SET_NULL, blank=True, null=True)
coupon = models.ForeignKey('Coupon',
on_delete= models.SET_NULL, blank=True, null=True)
processing = models.BooleanField(default=False)
aprouved = models.BooleanField(default=False)
refund_requested = models.BooleanField(default=False)
refund_granted = models.BooleanField(default=False)
def __str__(self):
return self.user.username
def get_total(self):
total = 0
for order_item in self.items.all():
total += order_item.get_final_price()
if self.coupon:
total -= self.coupon.amount
return total
The last line of code for the error traceback after the migration, i try python manage.py migrate but i get that at the last line.
File "C:\Users\18094\AppData\Local\Programs\Python\Python37\lib\sitepackages\django\utils\dateparse.py", line 107,
in parse_datetimematch = datetime_re.match(value)
Upvotes: 0
Views: 1310
Reputation: 769
This method I am suggesting is a quick but not to recommend for the project in a production environment. You could try this out.
Make sure you add your app in the installed app, delete all your migrations folders, all the pycache folders, as well as the .sqlite file, then run the commands python manage.py makemigrations
, python manage.py migrate
and then start the server.
You could also run this python manage.py makemigrations app_name
if the first command doesn't detect the migration
I hope this is helpful
Upvotes: 0
Reputation: 1355
The table might contain data that conflicts with the datatype, ie. one of your date fields.
Since this data is not critical, you can remove the data and start over. assuming your app is named orders
./manage.py migrate orders zero # migrate to 0000, deleting the table
./manage.py migrate orders # migrate forward to current state
Upvotes: 1