"Column 'model_id' can not be null" Django Cascade

0

I have a problem deleting 2 foreign keys from a foreign key. I'll explain better:

This is the credit card model hierarchy I have:

  • CreditCard
    • Customer
      • Address
      • Phone

I'm trying to delete the address and phone, then customer and creditcard. You are saying that I can not change the foreign key address and phone from the customer model to null.

(1048, "Column 'phone_id' cannot be null")

He is trying to do an update on the phone_id and address_id column by setting to NULL. The mistake was this, the operation is not allowed. It then assigns null=True, blank=True to the customer model and the error continues.

I tried this way:

_credit_card.customer.phone.delete()
_credit_card.customer.address.delete()
_credit_card.customer.delete()
_credit_card.delete()

Python 3, Django 1.10

    
asked by anonymous 12.07.2017 / 00:19

1 answer

-1

I have identified the problem. I had the 2 foreign key (UserPhone and UserAddress) inside the Customer table as foreign key. Even using on_delete=models.CASCADE was not working. It was only me who took out these 2 foreign keys and created the foreign key of the CUSTOMER within each of the tables that worked. Deleting Customer, I delete the 2 cascading tables.

    
14.07.2017 / 00:00