0

This is simplified version of my code

from cs50 import SQL

open("File_Name", "w").close()
db = SQL("sqlite:///File_Name")
id   =  2
filename="hola"
db.execute("insert into File_Name(id,File_name)values(?,?)",id,filename)

Terminal

~/login/ $ python hi.py Traceback (most recent call last): File "/home/ubuntu/login/hi.py", line 7, in db.execute("insert into File_Name(id,File_name)values(?,?)",id,filename) File "/usr/local/lib/python3.9/site-packages/cs50/sql.py", line 52, in execute return self._execute(statement, connection) File "/usr/local/lib/python3.9/site-packages/cs50/sql.py", line 71, in _execute raise RuntimeError(exc.orig) from None RuntimeError: no such table: File_Name

Please help me with this issue

4
  • That is a clear and unambiguous error. There is no table named "File_Name" in the database named "File_Name". If the intention of the open() is to create the database, then of course there is no table. Commented Sep 5, 2021 at 11:00
  • @DinoCoderSaurus I have saved a table named "File_Name" open() is used to open the file with table
    – Inderveer
    Commented Sep 5, 2021 at 12:35
  • The computer begs to differ. Are you in the right directory (ie where the actual database lives)? Not enough info in the question to proceed further. Try editing the database schema into the question to add context. There is no other explanation for the error message. There is no need to "open" the file with the table; that is done by cs50 library / SQL class. If there is no file named "File_Name" in the current working directory, the open command will create it, the db connect will not fail with "no such file" and you'll end up with this error message. Commented Sep 5, 2021 at 14:57
  • @DinoCoderSaurus @inderveer__singhofficial this is my telegram username you can add me and then i will give you access to ide and then you can help me.
    – Inderveer
    Commented Sep 5, 2021 at 16:30

2 Answers 2

1

This is a clear and unambiguous error message. The connected database ("File_Name" in ~/login directory) does not have a table named "File_Name".

Did you perhaps create the table in a database that lives in a directory other than ~/login? If so, cd to that directory to run the program -OR- use full path in the SQL instance create command (eg db = SQL("sqlite:///path_to_db/File_Name")).

If that's not the problem, then execute ls -al File_Name from ~/login directory. If size is 0 there are no tables. Create the desired table(s).

If size is not 0, use sqlite3 to examine the schema as described in the Understanding Section of the Movies exercise. Make sure the table exists (spelling counts!). If it does not, create it.

If the .schema command shows a table named "File_Name", please edit the question with the results of the ls and .schema commands (as text_)

0

You might have mis-spelled table names while defining FOREIGN KEYS. Database tries to create a connection in new table but the name provided as FOREIGN KEY table is not found.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .