Python Forum
How to create db table with SQLite and SQLAlchemy??
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create db table with SQLite and SQLAlchemy??
#1
Hi all I need urgent help I have been stuck on this for days!
I'm trying to create a table in an existing db with SQLAlchemy/SQLite where I have to store a user and password, but it returns an error saying the column pwd doesn't exist!
Am I missing something? Am I messig it up?
I still didn't quite understand, I followed all steps in some online tutorial but nothing still.
Here is the class object that I developed, then from another register form I try to store the pw from the application, but the error should be here in this code:
import os
basedir = os.path.abspath(os.path.dirname(__file__))

from flask import Flask 
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from sqlalchemy import *

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite')
engine= create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
bcrypt = Bcrypt(app)
db = SQLAlchemy(app)

#CREATE TABLE
meta=MetaData()
userstable = Table('users', meta, Column('id', Integer, primary_key = True, autoincrement=True), Column('username', String, unique=True), Column('pwd', String))
meta.create_all(engine)

class User(db.Model):
	#DEFINE COLUMNS TYPE
    id = db.Column(db.Integer(), primary_key=True, autoincrement=True)
    username = db.Column(db.String(64), unique=True)
    pwd = db.Column(db.String(128))

    def __init__(self,username,pwd):
        #self.id=id
        self.username=username
        self.pwd=bcrypt.generate_password_hash(pwd)

THIS IS THE ERROR
sqlalchemy.exc.OperationalError  OperationalError: (sqlite3.OperationalError) table user has no column named pwd [SQL: INSERT INTO user (username, pwd) VALUES (?, ?)] [parameters: ('ita_itf', '$2b$12$VmpTsd0o4uTLj0wGypGu7ujhzYHLlV8k9ekaIP1.yh5lUMMgOM4MC')]
Reply
#2
Then I switch to Stackoverflow because on this Forum no replies in 3 issues I have posted. Then you are forced to post it twice. bye
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a table with different sizes of columns in MS word pepe 8 1,414 Dec-08-2023, 07:31 PM
Last Post: Pedroski55
Question Using SQLAlchemy, prevent SQLite3 table update by multiple program instances Calab 3 701 Aug-09-2023, 05:51 PM
Last Post: Calab
  group by create pivot table python dawid294 1 1,258 Jun-22-2022, 06:13 PM
Last Post: Larz60+
  sqlalchemy could not find table 3lnyn0 4 6,486 Mar-30-2022, 12:36 PM
Last Post: Larz60+
  SQLALCHEMY - Not selecting data from table jamesaarr 4 2,178 Nov-02-2021, 03:02 PM
Last Post: Larz60+
  UPDATE SQLITE TABLE - Copy a fields content to another field. andrewarles 14 4,245 May-08-2021, 04:58 PM
Last Post: ibreeden
  Create SQLite columns from a list or tuple? snakes 6 8,513 May-04-2021, 12:06 PM
Last Post: snakes
  Unable to Update SQLite Table sambanerjee 5 2,865 Sep-30-2020, 12:21 PM
Last Post: Larz60+
  Create new column in new created table farhana88 1 1,781 Jun-09-2020, 07:20 AM
Last Post: buran
  how to use items combobox in table name sqlite in python hampython 1 2,624 May-24-2020, 02:17 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020