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
  Unable to Update SQLite Table sambanerjee 5 381 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 489 Sep-04-2020, 01:39 PM
Last Post: ibreeden
  Create new column in new created table farhana88 1 384 Jun-09-2020, 07:20 AM
Last Post: buran
  how to use items combobox in table name sqlite in python hampython 1 668 May-24-2020, 02:17 AM
Last Post: Larz60+
  Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 393 Apr-29-2020, 06:45 PM
Last Post: nisusavi
  Help! - How to create a Title for a Reportlab Table crabbylou 0 990 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 841 Dec-26-2019, 05:57 AM
Last Post: buran
  Create table with psycopg2 on postgreSQL DB yhecohen 2 885 Aug-23-2019, 05:56 AM
Last Post: massimo_m
  Updating records 1 to n on an SQLite table KevinBrown 2 676 Mar-30-2019, 05:02 PM
Last Post: KevinBrown
  sqlite: INSERT using a variable for table name DT2000 3 2,135 Feb-23-2019, 06:28 AM
Last Post: DT2000

Forum Jump:

User Panel Messages

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