Tablename with ID “Some_ID” doesn't exist. Per

2019-08-02 21:26发布

I have database with many tables; three of those which are interlinked via primary and foreign keys are "Vendor_Details" , "Channel_Details" and "MSO_Details"

models.py

class Vendor_Details(models.Model):
    class Meta:
        verbose_name_plural = "Vendor_Details"
    vendor_name = models.CharField(primary_key = True,max_length=50)
    mso_id = models.CharField(unique = True, max_length=20)

class Channel_Details(models.Model):
    class Meta:
        verbose_name_plural = "Channel_Details"
    channel_id = models.CharField(primary_key = True, max_length=20)
    vendor_name = models.ForeignKey(Vendor_Details, on_delete=models.CASCADE)
    channel_logo = models.CharField(max_length=50)
    channel_name = models.CharField(max_length=50)

class MSO_Details(models.Model):
    class Meta:
        verbose_name_plural = "MSO_Details"
    mso_id = models.ForeignKey(Vendor_Details, on_delete=models.CASCADE)
    channel_id = models.ForeignKey(Channel_Details, on_delete=models.CASCADE)
    channel_number = models.PositiveIntegerField()

So, Channel_Details is linked to Vendor_Details with vendor_name and MSO_Details is linked with Vendor_Details and Channel_Details with mso_id and channel_id respectively.

Now, I am inside Django's Administrator's MSO_Details table and trying to click on edit icon of CHANNEL ID column i get a new window opens with message Channel_ details with ID "CH6" doesn't exist. Perhaps it was deleted? May be this is because channel_id is primary key of reference table and DB will not allow the changes? But then the message should had been something different. How can i handle this situation? I clicked on edit for CH_006 and message shows CH6. I am confused whats going on here, what is django's DB refering to here? Note : I can very well add new CHANNEL_DETAILS after click add button.

标签: django
1条回答
神经病院院长
2楼-- · 2019-08-02 21:50

I had this kind problem for the last two days and the problem was 1. If on adding details to a new form initially, you do not add the right field required.(I was including both text and integers to a field that was only CharField)

2.The other solution when the error came again was to delete migrations and the database itself and create a new database again(Using the same database name).

查看更多
登录 后发表回答