"No such table" error, with different tablename as in query

89 views
Skip to first unread message

Michel Lavoie

unread,
Oct 7, 2018, 8:45:08 AM10/7/18
to Django users
Hi,

I've just upgrade my Django installation from 1.11 to 2.0, and then to 2.1, and am now getting a weird bug with one of my applications. Whenever I try to execute a view that either deletes or saves a transation in my "finance" app, I get the following error:

OperationalError at /finance/2/1776/delete_transaction/
no such table: main.finance_transactions

The SQL query is fine though, looking at the traceback. It shows the correct table name which is: finance_transaction

/srv/http/myserver/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py in execute

   
def execute(self, query, params=None):
       
if params is None:
           
return Database.Cursor.execute(self, query)
        query
= self.convert_query(query)
       
return Database.Cursor.execute(self, query, params)

Local vars
Variable Value
params
(1776,)
query
'DELETE FROM "finance_transaction" WHERE "finance_transaction"."id" IN (?)'
self

<django.db.backends.sqlite3.base.SQLiteCursorWrapper object at 0xb55cf608>

I checked the database and table finance_transaction is present. All views that just show data work fine, only the ones that modify data generate this error. The other apps from this instance all work 100% fine, only this one has this bug. I also didn't modify anything from the code for the Django upgrade, except a few changes to views.py and urls.py to turn of warnings.

Any idea what could be causing this? I looked at all lines from the traceback and can't see what could be changing the table name after the SQL string get created.

BTW, I get the same error from the auto-generated admin page when trying to delete a transaction, as well as a custom management script. Thus, it shouldn't be related to my views.py.

Thanks,

Michel

Matthew Pava

unread,
Oct 8, 2018, 9:46:58 AM10/8/18
to django...@googlegroups.com

Hi Michel,

The error states that there is no such table finance_transactions  with an s on the end.  Maybe you could show us your view code, but that would be the place that I would start at.

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dbdeafaf-1d6c-434e-8ac6-97a57a555e9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michel Lavoie

unread,
Oct 8, 2018, 10:30:19 AM10/8/18
to django...@googlegroups.com
Hi Matthew,

Thank you for the suggestion, but as I mentioned the error is not limited to my views.py; it's also present in the auto generated admin page. Basically in the example I gave, I call the delete() method from my transaction object, by id.

There's also the "main."prefix in the error that bothers me, in addition to the "s" at the end of the table name. But I'm sure that it doesn't come from my views.py, this error appeared after upgrading to 2.1. My app's code is on GitHub: https://github.com/miek770/huitcent/tree/master/finance

Thanks,

Michel

Matthew Pava

unread,
Oct 8, 2018, 10:52:09 AM10/8/18
to django...@googlegroups.com

Hi Michel,

I’ve reviewed your code and everything looks like it should be working fine.  Have you tried using a fresh, blank database?  Could it be an issue with your settings?

I can’t imagine what else it could be at the moment.

Thanks,

Matthew

Michal Petrucha

unread,
Oct 8, 2018, 11:23:05 AM10/8/18
to django...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On Mon, Oct 08, 2018 at 10:29:30AM -0400, Michel Lavoie wrote:
> Hi Matthew,
>
> Thank you for the suggestion, but as I mentioned the error is not limited
> to my views.py; it's also present in the auto generated admin page.
> Basically in the example I gave, I call the delete() method from my
> transaction object, by id.
>
> There's also the "main."prefix in the error that bothers me, in addition to
> the "s" at the end of the table name. But I'm sure that it doesn't come
> from my views.py, this error appeared after upgrading to 2.1. My app's code
> is on GitHub: https://github.com/miek770/huitcent/tree/master/finance
>
> Thanks,
>
> Michel

Hi Michel,

I also took a glance, and didn't find anything suspicious. Is there a
chance that you have multiple databases defined in your settings, and
a router that directs write queries for the Transaction model to the
wrong one?

Michal
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJbu3YYAAoJEHA7T/IPM/klrZ8P/1FAI/sm5UEMOUSnxjLM6fI+
/9Lu7/7ZhFvKFVXOSa6GT2pxEjOkdLmtmMwQv1ghvxgvCmVMEohOKoNDPDwhdEGA
VvYuBD7rNhmBqPTwGYdn2ci4fFIK3EaaMuv5pBkdW/ztWcyFgZaJFA1T8KEYR+nR
/8ZBcZOhcZAGpdqppCIZoJTPsHcRggAt2CGWvNzFC9BxFh3w+BqTfTkBLfa2ZQpg
MmBEpqu5VGsOIG3nlULnvnzBMhJEy8IkGf8TTmp0MUeRUycnRQnsCfIVjqDfQuGo
aetk6Jdb9C9760STJnPp7FAdtQqIYj8vdy0NU2KoM9hhxZk80YOuC1PCqDkteuRH
SmkwH5kI5FZKiKAeDUPBn4h2hvkMm/5B1kqtk+BzzAZPCY5CRkmJno+BjCWb0nFE
zSOA/i01a4hlEbhBNDjeYyxvuVVigGGXYBfLuuagIGz/61axu/pWn18sGElRqr+r
0T0c63QxuOtj6ZCJ5HrtMDRfzfnAjrRImqxmviQJo10XRKSsLavRYqIuKC1AgKFq
K+2c6cel4wb+n698FEAK24ic7gYR+ZH5kX0qOEXUMB2ND5DMKBKaqdkr7S3EqgIm
7KiuM/oL8SCxAdKKzJvvZyLwSgoDQxcAWng6YccWIZk5C5gcJHwI0wljjfPP0U3v
pUFCfu/sRN9umoHyryiF
=8Eai
-----END PGP SIGNATURE-----

Michel Lavoie

unread,
Oct 8, 2018, 2:16:18 PM10/8/18
to django...@googlegroups.com
Hi,

@Matthew: I've just tried with a blank database, and everything appeared to work perfectly. I couldn't reproduce the bug I'm seeing now. The database structure looks identical though; in both cases the table name is "finance_transaction", not "main.finance_transactions".

@Michal: I'm pretty sure the settings.py is ok, but here it is just in case. I wouldn't be here if I didn't think there was something wrong :) https://pastebin.com/yKzAjBcX (p.s.: Yes my secret is safe)

Thank you for your help, Matthew's suggestion gave me a possible solution (i.e. manually transfer my data to a new database), but I would like to avoid that if possible.

Michel Lavoie


--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Matthew Pava

unread,
Oct 8, 2018, 4:12:15 PM10/8/18
to django...@googlegroups.com

It almost seems like your database is corrupt.  Did you run migrations before running the server?

Michel Lavoie

unread,
Oct 8, 2018, 7:08:13 PM10/8/18
to Django users
I have (tried running migrations), although I didn't change my models and I'm not sure if I did it after or before the problem started.

You're probably right though, if the current database has issues but not the new one, the old one might have somehow been corrupted... It's probably a good time to switch to my PostgreSQL server. I'll do the transfer once I get a chance.

I still find it odd that Django reports a different table name than the traceback.

Thanks,

Michel

Reply all
Reply to author
Forward
0 new messages