Answer the question
In order to leave comments, you need to log in
Questions about sqlalchemy
1. Is it possible to get the names of the database columns using sqlalchemy and somehow manipulate them dynamically (without setting them directly in the class that maps)
2. How, in fact, to create / delete / edit columns
3. I have entries and tags with a many-to-many relationship through a third table, like the one here . How to correctly write a class for a link table, taking into account the fact that there is no primary key?
Answer the question
In order to leave comments, you need to log in
People's needs are growing, people are tired of static and want more dynamics.
Alas, SQL-based DBMS are not designed for dynamic schemas. If you often change the scheme, you will lose in performance, you will lose a lot. And this is despite the fact that SQL (and even more so using SA) is not so smart.
I advise you to pay attention to more modern solutions - document-oriented databases. More precisely - on MongoDB and MongoKit as a means for creating and manipulating schemas.
The fact is that document-oriented DBMSs are created just for dynamic data, where the schema can change frequently. A document in such a database is the same as a record (row, row) in SQL-based, relational databases.
The document is a JSON data structure in which everything can be changed, supplemented, deleted.
The document does not have a "schema". Those. wanted to make a document with a user post, so do it:
db.posts.save({id:1, author:"James", text:"Howdy!"})
However, schemas are needed, so software solutions like MongoKit are made for them .
For example, you can specify the following schema in MongoKit:
{
name:unicode,
data:{unicode:unicode}
}
Which will allow you to operate on the data dictionary as you like.
Scheme for the post, for example:
{
id:int,
author:unicode,
text:unicode
}
In general, I advise you to read:
www.mongodb.org/
namlook.github.com/mongokit/
thanks, I'll look in this direction, but still I would like to hear at least about the 3rd question,
because if I write
, I get the answer sqlalchemy.exc.ArgumentError: Mapper Mapper|tagged|tagged could not assemble any primary key columns for mapped table 'tagged '
but I would not want to make an extra field in the table
class tagged(Base):
__tablename__ = 'tagged'
elem = Column(Integer, key='elem')
tag = Column(Integer, key='tag')
def __init__(self, elem, tag):
self.elem = elem
self.tag = tag
Let's revive the corpse. :-)
SQLAlchemy requires a mandatory(!) presence of a primary key in the table.
As REDkiy said , just specify:
```
id = db.Column(db.Integer, primary_key=True)
```
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question