'Sqlite Database Access : No such table (Within Django no models)

I have a django & docker server running on my computer and I have created a database with code from outside this server. I am trying to access this database ('test.sqlite3') within the server.

I made sure the path was the correct one and that the file name was correct as well. When I open the database with DB Browser, I can see the tables and all my data. But I still get the following error text:

OperationalError no such table: NAMEOFTABLE

When I use the exact same code from another python IDE (spyder) it works fine. I'm guessing there's something weird going on with django?

Here is some of the code:

conn = sqlite3.connect("../test.sqlite3")
c = conn.cursor()
c.execute("SELECT firstName, lastName FROM RESOURCES")
conn.close()

(Yes, I have also tried using the absolute path and I get the same error.)

Also to be noted: I get this same error when I try to create the database file & table from within the django code (the path should then be the same but it still get the error in this case).

Update: it seems I have a problem with my path because I can't even open a text file with python and it's absolute path. So if anyone has any idea why that'd be great.

    try:
        f = open("/Users/XXXXX/OneDrive/XXXXX/XXXX/Autres/argon-dashboard-django/toto.txt")
        # Do something with the file
    except IOError:
        q="File not accessible"
    finally:
        f.close()

always return the following error 'f referenced before assignment' and q = "File not accesible" so that means I can't even find the text file.



Solution 1:[1]

Had a similar issue, possibly something about leaving Django Model metadata files outside of the image. I needed to synchronize the model with the DB using a run-syncdb

RUN ["python", "manage.py", "migrate"]
RUN ["python", "manage.py", "migrate", "--run-syncdb"]
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

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 Raul Lapeira Herrero