sqlalchemy

ImportError: No module named MySQLdb

纵饮孤独 提交于 2021-02-20 16:46:26
解决没有MySqldb的问题, Traceback (most recent call last): File " manage.py " , line 5 , in <module> from platform import app File " /CP/BlogSystem/platform.py " , line 16 , in <module> engine = create_engine( ' mysql://root:root@localhost/db_demo8 ' , echo= True) File " /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/__init__.py " , line 424 , in create_engine return strategy.create(*args, ** kwargs) File " /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py " , line 81 , in create dbapi = dialect_cls.dbapi(** dbapi_args) File " /usr/local/lib/python2.7/dist-packages

SQLAlchemy, Declarative, PostgreSQL: cannot create tables

感情迁移 提交于 2021-02-20 04:04:14
问题 I created a number of classes I want to persist to the database. I would like to be able to run the app with a specific flag to take all those classes and create the corresponding tables in my db. To that end, I'm trying to import the classes and then call the Base.metadata.create_all(engine) method. However, that doesn't work. At the same time, when I call that from the file with each of those actual classes, the tables are created. How do I go about the task of creating those tables? Should

Python postgreSQL sqlalchemy query a DATERANGE column

百般思念 提交于 2021-02-19 09:42:49
问题 I have a booking system and I save the booked daterange in a DATERANGE column: booked_date = Column(DATERANGE(), nullable=False) I already know that I can access the actual dates with booked_date.lower or booked_date.upper For example I do this here: for bdate in room.RoomObject_addresses_UserBooksRoom: unaviable_ranges['ranges'].append([str(bdate.booked_date.lower),\ str(bdate.booked_date.upper)]) Now I need to filter my bookings by a given daterange. For example I want to see all bookings

INSERT or UPDATE bulk data from dataframe/CSV to PostgreSQL database

帅比萌擦擦* 提交于 2021-02-19 08:57:05
问题 Requirement: Insert new data and update existing data in bulk (row count > 1000) from a dataframe/CSV (which ever suites) and save it in PostgreSQL database. Table: TEST_TABLE CREATE TABLE TEST_TABLE ( itemid varchar(100) NOT NULL PRIMARY KEY, title varchar(255), street varchar(10), pincode VARCHAR(100)); INSERT: ['756252', 'tom title', 'APC Road', '598733' ], ['75623', 'dick title', 'Bush Road', '598787' ], ['756211', 'harry title', 'Obama Street', '598733' ] dataframe content: data = [[

SQLAlchemy, reflection, different backends and table/column case insensitivity

▼魔方 西西 提交于 2021-02-19 07:53:09
问题 Intro: I'm writing web interface with SQLAlchemy reflection that supports multiple databases. It turns out that authors of application defined postgresql with lowercase tables/columns, eg. job.jobstatus while sqlite has mixed case, eg Job.JobStatus . I'm using DeclarativeReflectedBase from examples to combine reflection and declarative style. The issue: Configure SQLAlchemy to work with tables/columns case insensitive with reflection I have done so far: I have changed DeclarativeReflectedBase

SQLAlchemy, reflection, different backends and table/column case insensitivity

别说谁变了你拦得住时间么 提交于 2021-02-19 07:53:03
问题 Intro: I'm writing web interface with SQLAlchemy reflection that supports multiple databases. It turns out that authors of application defined postgresql with lowercase tables/columns, eg. job.jobstatus while sqlite has mixed case, eg Job.JobStatus . I'm using DeclarativeReflectedBase from examples to combine reflection and declarative style. The issue: Configure SQLAlchemy to work with tables/columns case insensitive with reflection I have done so far: I have changed DeclarativeReflectedBase

pyodbc to sqlalchemy connection

心已入冬 提交于 2021-02-19 07:16:26
问题 I am trying to switch a pyodbc connection to sqlalchemy. The working pyodbc connection is: import pyodbc con = 'DRIVER={ODBC Driver 11 for SQL Server};SERVER=server.com\pro;DATABASE=DBase;Trusted_Connection=yes' cnxn = pyodbc.connect(con) cursor = cnxn.cursor() query = "Select * from table" cursor.execute(query) I tried: from sqlalchemy import create_engine dns = 'mssql+pyodbc://server.com\pro/DBase?driver=SQL+Server' engine = create_engine(dns) engine.execute('Select * from table').fetchall(

Relationship to different tables in SQLalchemy

痞子三分冷 提交于 2021-02-19 06:57:25
问题 I have multiple tables. All tables have multiple columns that could not logically be stored in one merged table. class Foo(Model): foo_id = Column(Integer(unsigned=True), primary_key=True, nullable=False) foo_data = Column(...) class Bar(Model): bar_id = Column(Integer(unsigned=True), primary_key=True, nullable=False) bar_info = Column(...) class Baz(Model): baz_id = Column(Integer(unsigned=True), primary_key=True, nullable=False) baz_content = Column(...) Now I want to save changes in a

Sqlalchemy database int to python enum

狂风中的少年 提交于 2021-02-19 06:55:27
问题 I have lots of integers in my existing database which signify an enum. In my python project I have created the corresponding enums like so: class Status(Enum): OK = 0 PENDING = 1 CANCELED = 2 DUPLICATE = 3 INCOMING = 4 BLOCKED = 5 In my SQLalchemy models I'd like to be able to do the following status = Column(Status, nullable=False) Which should convert the database integers to python enums and back transparantly So far I've tried to inherit from the sqlalchemy.types.TypeDecorator and

SQLAlchemy cannot connect to Postgresql on localhost

。_饼干妹妹 提交于 2021-02-19 04:24:45
问题 I'm sure this is such an easy error to fix, if I could only find where it is. This is the error from the Flask app: 11:58:18 web.1 | ERROR:xxxxxx.core:Exception on / [GET] 11:58:18 web.1 | Traceback (most recent call last): 11:58:18 web.1 | File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app 11:58:18 web.1 | response = self.full_dispatch_request() 11:58:18 web.1 | File "/Library/Python/2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request 11:58:18 web