python - How To Delete A SQLite Table in SQL Alchemy ORM? -
so, here's problem
i making application on flask using sqlalchemy orm
now problem is, may have messed creating of table user;
in models.py code looks like,
class user(db.model): id = db.column(db.integer, primary_key=true) name = db.column(db.string(50)) username = db.column(db.string(25), unique=true) password = db.column(db.string(50)) email = db.column(db.varchar(50), unique=true) registerdate= db.column(db.datetime) def __init__(self, name, username, password, email, registerdate=none): self.name = name self.username = username self.password = password self.email = email if registerdate none: registerdate = datetime.utcnow() self.registerdate = registerdate
now, error like
operationalerror: table user has no column named user_name
this because messed table creation, creating table column "user_name" first, when gave me error related underscores, tried modify code instead ran error...
so how delete previous 'user' table in sql alchemy orm without using usual sqlite3 syntax , commands?
p.s : using ubuntu 16.04 python terminal, no ide atom or pycharm , stuff ...
alright ! after being confused 'engine' , ton of other technicalities regarding sqlite,
i have solution !
first enter python terminal through ubuntu terminal... , do,
yourproject import app,db yourproject import table1,table2....user #import classes data want manipulate import sqlite3 con = sqlite3.connect('absolute path db file') c = con.cursor() c.execute("drop table user;") db.session.commit() #i bit unsure 1
and that's it, that's how deleted troublesome 'user' table. created new 1 , works wonders !
also, user class code not formatted, in
def __init__(self,name,username,password,email,registerdate=none): self.name = name self.username = username self.password = password self.email = email if registerdate none: registerdate = datetime.utcnow() self.registerdate = registerdate
notice, how class parameters weren't in 'stairs' formation before? bugged me alot in creating table , adding data it. make sure take care of that.
this issue beginners might come across , find daunting, hope out !
cheers !
Comments
Post a Comment