Hello, Thanks for the suggestion. I actually changed it to the following to as to not have the "_id" suffix:
filename_number = models.ForeignKey(FilenameTbl,db_column='filename_number', to_field='rowid',null=True,blank=True,on_delete=models.SET_NULL) This is what eventually worked for me: https://stackoverflow.com/questions/68537031/how-do-i-resolve-the-following-error-in-django-operationalerror-foreign-key-m Cheers, Wai On Mon, Jul 26, 2021 at 9:32 PM DJANGO DEVELOPER <[email protected]> wrote: > can you please change your object from this: > filename_id = models.ForeignKey(FilenameTbl,db_column='filename_id', > to_field='rowid',null=True,blank=True,on_delete=models.SET_NULL) > to : > filename_id = models.ForeignKey(FilenameTbl,db_column='filename', > to_field='rowid',null=True,blank=True,on_delete=models.SET_NULL) > > On Tue, Jul 27, 2021 at 1:53 AM Wai Yeung <[email protected]> wrote: > >> Hello, >> >> I'm getting the following error whenever I attempt to save to the table >> in a SQLite database: >> >> foreign key mismatch - "procedure_tbl" referencing "filename_tbl" >> >> In models.py, these are the tables that the error is refering to: >> >> class FilenameTbl(models.Model): >> rowid = models.AutoField(auto_created=True, primary_key=True, >> serialize=False, verbose_name='FileID', db_column='rowid') >> filename = models.TextField(blank=True, null=True) >> creation_datetime = models.TextField(blank=True, null=True) >> >> class Meta: >> managed = False >> db_table = 'filename_tbl' >> ordering = ['rowid'] >> >> >> class ProcedureTbl(models.Model): >> rowid = models.AutoField(auto_created=True, primary_key=True, >> serialize=False, verbose_name='ProcedureID', db_column='rowid') >> ... >> filename_id = models.ForeignKey(FilenameTbl,db_column='filename_id', >> to_field='rowid',null=True,blank=True,on_delete=models.SET_NULL) >> >> class Meta: >> managed = False >> db_table = 'procedure_tbl' >> ordering = ['rowid'] >> >> Data can be read from the tables and querysets like the following return >> the correct data: >> queryset = FilenameTbl.objects.values( >> 'rowid', 'filename', >> 'proceduretbl__rowid') >> >> Raw SQLite commands to write/update to the ProcedureTbl table function >> properly. >> >> If I removed filename_id from the ProcedureTbl, then data can be saved to >> the table. >> >> Any insight into the issue would be much appreciated. >> >> Cheers, >> Wai >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/b90d237f-8c29-42ef-897a-34221704699dn%40googlegroups.com >> <https://groups.google.com/d/msgid/django-users/b90d237f-8c29-42ef-897a-34221704699dn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to a topic in the > Google Groups "Django users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-users/nqYRTN3m6Bg/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAKPY9pkH2pp3bkARsviqUdmn007Hc30ckrVOPH4yTBakJqXjDw%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAKPY9pkH2pp3bkARsviqUdmn007Hc30ckrVOPH4yTBakJqXjDw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKDLG%3DTx_oX5o7fhW9aaeMcyXsqhB2GsqRujLAxy1HVi3QjBPg%40mail.gmail.com.

