flask-sqlalchemy

update state with flask sqlalchemy with postgres will not commit to database

只愿长相守 提交于 2019-12-04 07:09:56
问题 I have read quite a bit of documentation and I can't see what is wrong with these lines update_this = User.query.filter_by(email=email).first() update_this.emailconfirmed = True db.session.commit() ...and yet when I deploy the boolean column 'emailconfirmed' never is update to True. I have confirmed with print statements that update_this.emailconfirmed is False at the exact point in the code shown above... I just can't seem to update that value. Does anybody know what tests I can do, what

Flask SqlAlchemy join two models without foreign key MYSQL

夙愿已清 提交于 2019-12-04 05:45:59
I am joining two models without a foreign key: Models: class Users(db.Model): __tablename__ = "Users" userName = db.Column(db.String, primary_key=True) lastLogin = db.Column(db.DateTime) class TimeOff __tablename__ = "timeOff" timeOffID = db.Column(db.Integer, primary_key=True) userName = db.Column("userName", db.String, db.ForeignKey('appUsers.userName')), dayWork = db.Column(db.DateTime) View: result = db.session.query(models.Users).join(models.TimeOff) sqlalchemy.exc.InvalidRequestError: Could not find a FROM clause to join from. Tried joining to but got: Can't find any foreign key

Flask_SQLAlchemy, MySQL, store Swedish characters å, ä, ö?

孤人 提交于 2019-12-04 05:45:33
问题 I can't sto re Swedish characters in MySQL by using Flask_SQLAlchemy :( I have tried to find a solution for a week now and I really need help as it feels like I have reached a dead end. I think it could be something wrong with the version compatibilities abong my tools, but I don't hope so! I am trying to build an website using Flask, Flask_SQLAlchemy and MySQL (5.5.3). If this is unsolvable, I am considering changing Flask_SQLAlchemy to something else.. (I have taken one course in

How to return “already exists” error in Flask-restless?

﹥>﹥吖頭↗ 提交于 2019-12-04 05:40:50
I would like to do some handler for exception. I'm using a combination of Flask-restless and SQLAlchemy in python. My problem: When I send request to api with object that already exists in DB, SQLAlchemy shows exception: IntegrityError: (IntegrityError) column <column_name> is not unique u'INSERT INTO ... So I have tried to add attribute validation_exceptions into create_api method: manager.create_api( ... , validation_exceptions=[IntegrityError]) But response json contains: { "validation_errors": "Could not determine specific validation errors" } and server api shows exception : Traceback

Flask foreign_keys still shows AmbiguousForeignKeysError

廉价感情. 提交于 2019-12-04 05:31:43
I have two foreign keys in an entity refering to another entity. Here is how it looks class Review(db.Model): __tablename__ = 'Review' id = db.Column(db.Integer, primary_key = True) user_id = db.Column(db.Integer, db.ForeignKey('User.id'), nullable=False) business_user_id = db.Column(db.Integer, db.ForeignKey('User.id'), nullable=False) user = db.relationship('User', foreign_keys=[user_id]) business_user = db.relationship('User', foreign_keys=[business_user_id]) and class User(db.Model): __tablename__ = 'User' id = db.Column(db.Integer, primary_key = True) reviews = db.relationship('Review',

Many-to-many multi-database join with Flask-SQLAlchemy

谁说我不能喝 提交于 2019-12-04 05:29:45
I'm trying to make this many-to-many join work with Flask-SQLAlchemy and two MySQL databases, and it's very close except it's using the wrong database for the join table. Here's the basics... I've got main_db and vendor_db . The tables are setup as main_db.users , main_db.user_products (the relation table), and then vendor_db.products . Should be pretty clear how those are all connected. in my app.py, I'm seting up the databases like this: app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://user:pass@localhost/main_db' app.config['SQLALCHEMY_BINDS'] = { 'vendor_db': 'mysql://user:pass@localhost

Querying from list of related in SQLalchemy and Flask

巧了我就是萌 提交于 2019-12-04 03:37:26
I have User which has-one Person . So User.person is a Person . I am trying to get a list of User from a list of Person . I tried the following: >>> people = Person.query.filter().limit(3) <flask_sqlalchemy.BaseQuery object at 0x111c69bd0> >>> User.query.filter(User.person.in_(people)).all() NotImplementedError: in_() not yet supported for relationships. For a simple many-to-one, use in_() against the set of foreign key values. What is the best way to get a list of User s where User.person is in that list of people ? As the error message helpfully tells you, you need to use in_ against the

Create many to many on one table

大城市里の小女人 提交于 2019-12-04 03:35:18
问题 Flask-SQLAlchemy gives an example of how to create a many to many relationship. It is done between two different tables. Is it possible to create a many to many relationship on the same table? For example a sister can have many sisters, who would also have many sisters. I have tried: girl_sister_map = db.Table('girl_sister_map', db.Column('girl_id', db.Integer, db.ForeignKey('girl.id')), db.Column('sister_id', db.Integer, db.ForeignKey('girl.id'))) class Girl(db.Model): id = db.Column(db

SQLAlchemy chaining association proxy for great grandchildren?

别等时光非礼了梦想. 提交于 2019-12-04 02:53:37
I have a four classes like so: Group , Parent , Child , Toy . Group has a parents relationship pointing to Parent Parent has a children relationship pointing to Child Child has a toys relationship pointing to Toy Parent has a toys association_proxy that produces all the Toy s that the Parent 's children have. I want to be able to get all the Toys in a Group. I tried to create an association_proxy on Group that links to Parent 's toys , but it produces this: [[<Toy 1>, <Toy 2>], [], [], []] when I want this: [<Toy 1>, <Toy 2>] If the Parent 's children don't have any Toy s, then the toys

Flask-SQLAlchemy - When are the tables/databases created and destroyed?

…衆ロ難τιáo~ 提交于 2019-12-04 00:11:38
I am a little confused with the topic alluded to in the title. So, when a Flask app is started, does the SQLAlchemy search the SQLALCHEMY_DATABASE_URI for the correct, in my case, MySQL database. Then, does it create the tables if they do not exist already? What if the database that is programmed into the SQLALCHEMY_DATABASE_URI variable in the config.py file does not exist? What if that database exists, and only a few of the tables exist (There are more tables coded into the SQLAlchemy code than exist in the actual MySQL database)? Does it erase those tables and then create new tables with