Hello,
I have a weird situation, I am at lesson 25 - Transactions (Django ORM) and I tried this code
with transaction.atomic():
order = Order()
order.customer_id = -1
order.save()
item = OrderItem()
item.order = order
item.product_id = 2012
item.quantity = 1
item.unit_price = 10
item.save()
in the video I see that Mosh got an IntegrityError ( Cannot add or update a child row: a foreign key constraint fails ). I am using mysql-connector-python instead of mysqlclient , I have to use this because I have a managed VPS where I cannot install mysqlclient ( it depends on 2 other linux libraries and I am not able to install those libraries ). My DB settings looks like this:
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'storefront',
'USER': 'root',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '3306',
'OPTIONS': {
'use_pure': True,
}
}
}
MySQL db collation is utf8_general_ci.
So the problem is that my code runs without any error and inserts and order with customer_id -1 which doesn’t exists and an orderItem with product_id 2012 which also doesn’t exists.
I use the same model like Mosh used in his lesson.
I would appreciate any help regarding this weird situation.
Thank you.