Answer the question
In order to leave comments, you need to log in
How to fix error while creating SQLAlchemy table?
Hello!
Unable to create sqllite table. When creating a table in the python console, I use the commands
>>> from main import db
>>> db.create_all() It throws an
error AttributeError: can't set attribute
Here is my application code:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///tmp/dpd_test.db '
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
@app.route('/')
def hello_world():
return 'Hello, World!'
Answer the question
In order to leave comments, you need to log in
Perhaps the problem is in the path to the db.
Try replacing this
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///tmp/dpd_test.db '
import os
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join( os.path.abspath(os.path.dirname(__file__)), 'mydb.db' )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question