'Python Django Operational error, no such table

I'm trying to use a sqlite database from a different project in my django project. I've added the .db file to my project structure and added the following code (new database contains info about companies):

In settings.py:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': BASE_DIR / 'db.sqlite3',
},
'companies':{
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': BASE_DIR / 'companies/db/company_financials002.db'
}
}

In companies/admin.py:

from .models import Companies, RowData, StatementRows, Statements

admin.site.register(Companies)
admin.site.register(RowData)
admin.site.register(StatementRows)
admin.site.register(Statements)

Next, I ran the manage.py makemigrations and migrate

If I log into the admin panel, all tables are shown: admin panel However, if I try to access a table it hits me with an operational error/no such table: error message

The autogenerated models says in the top comments: Remove managed = False lines if you wish to allow Django to create, modify, and delete the table so I did.

I'm really at a loss as to how to acces my data now and I can't seem to find the solution anywhere on the internet.



Solution 1:[1]

I think the issue is related to the path for your DB.

'NAME': BASE_DIR / 'companies/db/company_financials002.db'

In the above line of code. Make sure the folder "companies" is located in the same folder where your manage.py is located.

( I'm just a beginner, but this error seems familiar to me, that's why I'm answering )

Solution 2:[2]

Okay so if anyone were to end up on this page with the same problem; I found the issue.

The db file I created in a different project. In this project, decimals and null are supposed to be inserted to the table. However, in the sql command, the value being inserted is surrounded by 'quotation marks'.

This means it's essentially inserting something else than a decimal (a string). This is possible. But when retreiving the value with Django, it's expecting a decimal and gets something else.

Removing the quotation marks, re-exporting the db file and using the new one did the trick.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HIMANSHU KAWALE
Solution 2 y3ll0ww