sqlalchemyでschemaを宣言して、__init__で代入した時の挙動でちょっと躓いたのでめもです。 問題 たとえば、todo管理ツールを作るとして、UesrとTaskを作ります。 Taskの順番をpositionとして保持しようとしたときに以下のようなコードにしたとします。 # coding=utf-8 from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import( Column, Integer, String, create_engine, ForeignKey, ) from sqlalchemy.orm import ( scoped_session, sessionmaker, relationship, ) Base = declarative_base() class
![sqlalchemyの初期化で悩んだこと - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/5546757b9a163a1e10bf72e1ce60d8be253ff872/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Fogp-background-1150d8b18a7c15795b701a55ae908f94.png%3Fixlib%3Drb-1.2.2%26w%3D1200%26mark%3Dhttps%253A%252F%252Fqiita-user-contents.imgix.net%252F~text%253Fixlib%253Drb-1.2.2%2526w%253D840%2526h%253D380%2526txt%253Dsqlalchemy%2525E3%252581%2525AE%2525E5%252588%25259D%2525E6%25259C%25259F%2525E5%25258C%252596%2525E3%252581%2525A7%2525E6%252582%2525A9%2525E3%252582%252593%2525E3%252581%2525A0%2525E3%252581%252593%2525E3%252581%2525A8%2526txt-color%253D%252523333%2526txt-font%253DAvenir-Black%2526txt-size%253D54%2526txt-clip%253Dellipsis%2526txt-align%253Dcenter%25252Cmiddle%2526s%253D5e43e3fcbf83293d2afabbca6cc305aa%26mark-align%3Dcenter%252Cmiddle%26blend%3Dhttps%253A%252F%252Fqiita-user-contents.imgix.net%252F~text%253Fixlib%253Drb-1.2.2%2526w%253D840%2526h%253D500%2526txt%253D%252540cocuh%2526txt-color%253D%252523333%2526txt-font%253DAvenir-Black%2526txt-size%253D45%2526txt-align%253Dright%25252Cbottom%2526s%253D7cbf3fd497991b31620d142e4e67dbff%26blend-align%3Dcenter%252Cmiddle%26blend-mode%3Dnormal%26s%3Ddbb1a10362b608699d81b49f0334f9e5)