flask-sqlalchemy

Flask-sqalchemy and oracle database id not autoincrement

北慕城南 提交于 2019-12-02 06:05:08
I want to make a new table in my database (Oracle 11g but the Express Edition for Ubuntu 16.04) using Python and Flask framework with the SQLAlchemy module. The first field of the table it's and ID, is an Integer field and I want it to autoincrement, but Oracle database don't support the autoincrement. I have a form to add a new comment, but when I try to add a new record it reports a error: sqlalchemy.exc.IntegrityError: (cx_Oracle.IntegrityError) ORA-01400: cannot insert NULL into ("WIKTOR"."TBL_COMENTARIOS"."ID") [SQL: 'INSERT INTO tbl_comentarios (usuario, comentario, fecha) VALUES (

Python SQLAlchemy: Reflecting the database breaks default/onupdate methods?

北城以北 提交于 2019-12-02 04:36:22
问题 I have two separate SQLAlchemy interfaces to a Postgres database. The first interface, in the context of a Flask App, contains this model: app = create_app() # sets the SQLAlchemy Database URI, etc. db = SQLAlchemy(app) class User(db.Model): id = db.Column(db.Integer, primary_key=True) created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow) updated_at = db.Column(db.DateTime, onupdate=datetime.datetime.utcnow) name = db.Column(db.String, nullable=False) The second interface is

sqlalchemy.exc.InterfaceError: <unprintable InterfaceError object>

让人想犯罪 __ 提交于 2019-12-02 04:04:41
问题 I'm trying out Flask but I'm having the error sqlalchemy.exc.InterfaceError: <unprintable InterfaceError object> while submitting a wtforms. The model class is: class Post(db.Model): __tablename__ = 'blog_posts' id = db.Column(db.Integer, unique=True, primary_key=True) title = db.Column(db.String(50), unique=False) content = db.Column(db.Text, unique=False) user_id = db.Column(db.String, db.ForeignKey('users.username')) @staticmethod def post_new_entry(title, content, user_id): """ Post new

Flask inherited classes of tables in multiple identical databases using __bind_key__

喜夏-厌秋 提交于 2019-12-02 03:03:34
I'm trying to build an admin control panel that brings together 4 different ecommerce sites. The sites all have identical database structures (all MySQL). What's Going Wrong? I get 404 Not Found on any order ID and site I put in. No matter how I mix it I can not get any record to come up. Always a 404 and I have no idea why. SO here I am. Code I tried to do this by creating base model classes of every table. Then creating inherited clases of those base classes with a different bind key dependent on the DB it is meant for. This is a summarised view of the code - if you'd need anymore than this

sqlalchemy.exc.InterfaceError: <unprintable InterfaceError object>

≡放荡痞女 提交于 2019-12-02 01:33:15
I'm trying out Flask but I'm having the error sqlalchemy.exc.InterfaceError: <unprintable InterfaceError object> while submitting a wtforms. The model class is: class Post(db.Model): __tablename__ = 'blog_posts' id = db.Column(db.Integer, unique=True, primary_key=True) title = db.Column(db.String(50), unique=False) content = db.Column(db.Text, unique=False) user_id = db.Column(db.String, db.ForeignKey('users.username')) @staticmethod def post_new_entry(title, content, user_id): """ Post new entry to database """ new_post = Post(title=title, content=content, user_id=user_id) db.session.add(new

Getting Flask-Migrate to Ignore SQL Views that are mapped as Flask-SQLAlchemy Models

谁说我不能喝 提交于 2019-12-01 21:46:46
问题 I am using Flask-SQLAlchemy to define my models, and then using Flask-Migrate to auto-generate migration scripts for deployment onto a PostgreSQL database. I have defined a number of SQL Views on the database that I use in my application like below. However, Flask-Migrate now generates a migration file for the view as it thinks it's a table. How do I correctly get Flask-Migrate / Alembic to ignore the view during autogenerate? SQL View name: vw_SampleView with two columns: id and rowcount .

Can't load JSON data to jQuery sqlalchemy-datatable

被刻印的时光 ゝ 提交于 2019-12-01 21:24:27
I'm having troubles on loading JSON data to a datatable. Here it is my Python code to perform that (do the query to the database and return that data with jsonify): @users_blueprint.route('/data') def data(): """Return server side data.""" # defining columns columns = [ ColumnDT(User.firstname), ColumnDT(User.lastname), ColumnDT(User.email), ColumnDT(User.urole) ] # defining the initial query users = db.session.query(User).all() # GET parameters params = request.args.to_dict() # instantiating a DataTable for the query and table needed rowTable = DataTables(params, users, columns) print "AHHAX"

SQLAlchemy: Any constraint to check one of the two columns is not null?

浪子不回头ぞ 提交于 2019-12-01 20:49:23
问题 This may be totally stupid thing to ask but I have such a requirement in my model where atleast either category or parent_category is not null My model looks like class BudgetCategories(db.Model): __tablename__ = 'budget_categories' uuid = Column('uuid', GUID(), default=uuid.uuid4, primary_key=True, unique=True) budget_id = Column(GUID(), ForeignKey('budgets.uuid'), nullable=False) budget = relationship('Budget', backref='budgetCategories') category = Column('category', sa.types.String,

SQLAlchemy: Any constraint to check one of the two columns is not null?

ⅰ亾dé卋堺 提交于 2019-12-01 20:45:16
This may be totally stupid thing to ask but I have such a requirement in my model where atleast either category or parent_category is not null My model looks like class BudgetCategories(db.Model): __tablename__ = 'budget_categories' uuid = Column('uuid', GUID(), default=uuid.uuid4, primary_key=True, unique=True) budget_id = Column(GUID(), ForeignKey('budgets.uuid'), nullable=False) budget = relationship('Budget', backref='budgetCategories') category = Column('category', sa.types.String, nullable=True) parent_category = Column('parent_category', sa.types.String, nullable=True) amount = Column(

SQLAlchemy circular one-to-one relationship

做~自己de王妃 提交于 2019-12-01 19:24:42
I am trying to make a circular one-to-one relationship (not sure what the correct term is) with SQLAlchemy that looks the following: class Parent(Base): __tablename__ = 'parents' id = db.Column(Integer, primary_key=True) child_id = db.Column(db.Integer,db.ForeignKey("children.id", use_alter=True)) child = db.relationship("Child", uselist=False, foreign_keys=[child_id], post_update=True) class Child(Base): __tablename__ = 'children' id = db.Column(db.Integer, primary_key=True) parent_id = db.Column(db.Integer, db.ForeignKey("parents.id")) user = db.relationship("Parent", uselist=False, foreign