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??
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)

userstable = Table('users', meta, Column('id', Integer, primary_key = True, autoincrement=True), Column('username', String, unique=True), Column('pwd', String))

class User(db.Model):
    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):

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')]
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

Possibly Related Threads…
Thread Author Replies Views Last Post
  SQLALCHEMY - Not selecting data from table jamesaarr 4 340 Nov-02-2021, 03:02 PM
Last Post: Larz60+
  UPDATE SQLITE TABLE - Copy a fields content to another field. andrewarles 14 1,464 May-08-2021, 04:58 PM
Last Post: ibreeden
  Create SQLite columns from a list or tuple? snakes 6 1,862 May-04-2021, 12:06 PM
Last Post: snakes
  Unable to Update SQLite Table sambanerjee 5 1,245 Sep-30-2020, 12:21 PM
Last Post: Larz60+
  Fetch Oracle DB rows & print it in HTML file with table's col headers in table format tssr_2001 1 1,393 Sep-04-2020, 01:39 PM
Last Post: ibreeden
  Create new column in new created table farhana88 1 918 Jun-09-2020, 07:20 AM
Last Post: buran
  how to use items combobox in table name sqlite in python hampython 1 1,325 May-24-2020, 02:17 AM
Last Post: Larz60+
  Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 937 Apr-29-2020, 06:45 PM
Last Post: nisusavi
  Help! - How to create a Title for a Reportlab Table crabbylou 0 2,563 Mar-29-2020, 09:14 PM
Last Post: crabbylou
  MYSQL how to assign a table for each user in my username table database? YoshikageKira 1 1,522 Dec-26-2019, 05:57 AM
Last Post: buran

Forum Jump:

User Panel Messages

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