Insert Data "Gagal" menggunakan peewee di python

Jadi saya kemarin ngikutin tutorial di kelas belajar peewee di python

mau create data baru di sqlite

user.py

from peewee import *
sqlite_db = SqliteDatabase('user.db')

class User(Model):
    name = CharField()
    email = CharField()

    class Meta:
        database = sqlite_db

sqlite_db.connect()
sqlite_db.create_tables([User], safe = True)

#insert Data
User.create(name = 'test', email = 'hehe@test')

nah saat saya jalanin kodenya pakai perintah

python user.py

muncul eror seperti ini

Traceback (most recent call last):
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 3160, in execute_sql
    cursor.execute(sql, params or ())
sqlite3.OperationalError: table user has no column named name

During handling of the above exception, another exception occurred:

Traceback (most recent call last):  File "F:\BELAJAR\oop_python\databases\user.py", line 17, in <module>
    User.create(name = 'test', email = 'hehe@test')
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 6393, in create
    inst.save(force_insert=True)
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 6603, in save
    pk = self.insert(**field_dict).execute()
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 1911, in inner
    return method(self, database, *args, **kwargs)
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 1982, in execute
    return self._execute(database)
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 2761, in _execute
    return super(Insert, self)._execute(database)
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 2479, in _execute
    cursor = database.execute(self)
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 3173, in execute
    return self.execute_sql(sql, params, commit=commit)
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 3157, in execute_sql
    with __exception_wrapper__:
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 2933, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 191, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\ErPrasetyo\AppData\Local\Programs\Python\Python310\lib\site-packages\peewee.py", line 3160, in execute_sql
    cursor.execute(sql, params or ())
peewee.OperationalError: table user has no column named name

saya udah cek sesuai demonya bang hilman ramadan, tapi masih error

terima kasih, mohon pencerahannya

avatar ErwinPrasetyo
@ErwinPrasetyo

36 Kontribusi 4 Poin

Dipost 2 tahun yang lalu

Tanggapan

Pertanyaan kamu tidak jelas, coba dijelaskan lebih baik

1 Jawaban:

<div>setelah saya ulik kembali ternyata masalahnya adalah disini saya sudah membuat file user.db itu karena ada ketimpangan data di file user.db<br><br>solusinya saya hapus isi file yang ada di user.db ,&nbsp;<br>lalu saya jalanin<br><br></div><pre>python user.py</pre><div><br></div><div>erornya pun hilang</div>

avatar ErwinPrasetyo
@ErwinPrasetyo

36 Kontribusi 4 Poin

Dipost 2 tahun yang lalu

Login untuk ikut Jawaban