1

I wrote a query to create a SQLite database and the query is completely correct. The database file is created in my project files but when I try to open it (in pycharm), this message shows up:

The file was loaded in a wrong encoding 'UTF-8'

This is the code causing this problem :

import sqlite3
connection = sqlite3.connect("./one_database.db")
cursor = connection.cursor()
sql = """
CREATE TABLE IF NOT EXISTS User (
    user_NAME VARCHAR (60),
    user_CHATID FLOAT (20),
    user_PHONENUMBER VARCHAR )
"""
cursor.execute(sql)
connection.commit()
connection.close()

So far, I tried to download and update all drivers and needs for SQLite3 and everything is up to date. I've tried all solutions I found on Google (including JetBrains official documentation, Stack Overflow, etc.) but none of the above is working and the result is the same!

I'm using: Python 3.8 | PyCharm 2021.1

  • 1
    Are you trying to open the database in a text editor? – Shawn Apr 10 '21 at 20:30
  • I don't have an SQLite DB installed so I can't test this, but [perhaps this is one of the better threads on the issue](https://stackoverflow.com/q/43153703) I didn't find any direct hit in the API, [this was the closest](https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.text_factory) about Unicode (you can try it). There's even a [youtube vid](https://www.youtube.com/watch?v=QThXaIyi2EY) and [lots of google hits](https://www.google.com/search?&q=%22The+file+was+loaded+in+a+wrong+encoding+%27UTF-8%27%22+sqlite3+python) – bad_coder Apr 10 '21 at 20:51
  • Anyway, most occurrences of this error seem to be specific to the JetBrains family of products, it seems the main issue is that one (or several) of your files have the wrong encoding. so you have to convert or delete them. (This happened to me once by copy-pasting something in the wrong encoding from outside the IDE). Try deleting that file to see if the encoding problem is only with that file, if it is try creating it again double-checking encoding and sanitizing the copy-paste, if that doesn't solve it try the solution linked from the API. – bad_coder Apr 10 '21 at 20:52
  • 1
    Yes, and like Shawn said: don't try to open DB binary files in the editor (the editor will expect UTF-8 and and complain the file isn't in that encoding.) – bad_coder Apr 10 '21 at 20:57
  • Hi @Shawn , yes ! as you may probably know , in pycharm , there is a primary tool for data bases to show the tables , records etc . back then , there was no problem with that but today it's suffering me . I'll try to open it somwhere else , thank you . – Behrad Edraki Apr 10 '21 at 21:11
  • thank you again @bad_coder for your time . yeah I checked them all but none of them helped me . I'm thinking about using "DB.Browser" which is a better tool to deal with SQLite databases . I'll let you know if that worked . – Behrad Edraki Apr 10 '21 at 21:13
  • "I tried to download and update all drivers and needs for SQLite3" FYI this isn't a thing for SQLite. SQLite is implemented as a library; there are no "drivers" for it like in other databases. – Colonel Thirty Two Apr 11 '21 at 01:05

1 Answers1

0

By the way I fixed my problem using "db.browser" ! This is used for deal with sqlite databases .