Create a base model classAre static class variables possible in Python?How can I safely create a nested directory?using flask-sqlalchemy without the subclassed declarative baseHow to use flask-sqlalchemy with existing sqlalchemy model?SQLAlchemy Reflection Using Metaclass with Column OverrideHow to inherit from another model in a view in SQLAlchemyUsing SqlAlchemy Models in flaskSQLAlchemy; getting list of related tables/classesFlask-Sqlalchemy multiple databases (binds) with the same model (class DB.Model)Flask SQLAlchemy: How to extend the base Model class?
How were Martello towers supposed to work?
Great Unsolved Problems in O.R
What is this little owl-like bird?
How to drill holes in 3/8" thick steel plates?
Switching interface VLAN ID Mid-Production
Killing Magic Numbers: "const int" vs "constexpr int" (or is there no difference in the end)
Is there a strong legal guarantee that the U.S. can give to another country that it won't attack them?
How can I effectively communicate to recruiters that a phone call is not possible?
What's it called when the bad guy gets eaten?
How can I get a player to accept that they should stop trying to pull stunts without thinking them through first?
Civic overheating and hoses popping
GDPR rights when subject dies; does family inherit subject rights?
Single word for "refusing to move to next activity unless present one is completed."
How quality assurance engineers test calculations?
Are there any sports for which the world's best player is female?
Plotting a function defined by equation without closed form solution
Does Multiverse exist in MCU?
Misspelling my name on my mathematical publications
How are mathematicians paid to do research?
Received a dinner invitation through my employer's email, is it ok to attend?
String manipulation with std::adjacent_find
How can I fix the dull colors I am getting in Ubuntu 19.04 Terminal?
DFT vs. MP2 for stacked dimer
Do I have a right to cancel a purchase of foreign currency in the UK?
Create a base model class
Are static class variables possible in Python?How can I safely create a nested directory?using flask-sqlalchemy without the subclassed declarative baseHow to use flask-sqlalchemy with existing sqlalchemy model?SQLAlchemy Reflection Using Metaclass with Column OverrideHow to inherit from another model in a view in SQLAlchemyUsing SqlAlchemy Models in flaskSQLAlchemy; getting list of related tables/classesFlask-Sqlalchemy multiple databases (binds) with the same model (class DB.Model)Flask SQLAlchemy: How to extend the base Model class?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm using flask-sqlalchemy.
I currently declare my models using:
class MyModel(db.Model):
__tablename__ = 'my_table'
id = db.Column(db.Integer, primary_key=True)
...
I want to create a base model class so I will be able to declare my models like this:
class MyBase(db.Model):
pass
class MyModel(MyBase):
__tablename__ = 'my_table'
id = db.Column(db.Integer, primary_key=True)
...
Is it possible?
I'm getting the following error:
InvalidRequestError: Class <class 'api.models.base.base_model.BaseModel'> does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class.
I would want to be able to put the tablename and all the column attributes inside my model and not inside my base class.
python sqlalchemy flask-sqlalchemy
add a comment |
I'm using flask-sqlalchemy.
I currently declare my models using:
class MyModel(db.Model):
__tablename__ = 'my_table'
id = db.Column(db.Integer, primary_key=True)
...
I want to create a base model class so I will be able to declare my models like this:
class MyBase(db.Model):
pass
class MyModel(MyBase):
__tablename__ = 'my_table'
id = db.Column(db.Integer, primary_key=True)
...
Is it possible?
I'm getting the following error:
InvalidRequestError: Class <class 'api.models.base.base_model.BaseModel'> does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class.
I would want to be able to put the tablename and all the column attributes inside my model and not inside my base class.
python sqlalchemy flask-sqlalchemy
What is the purpose of an empty base class?MyBase = db.Model
would seem to work just as well.
– chepner
Aug 25 '15 at 17:08
The base class will not be empty, I was just trying to give an example of what I was trying to do. I will add functionality to it of course.
– stefanobaldo
Aug 25 '15 at 18:03
add a comment |
I'm using flask-sqlalchemy.
I currently declare my models using:
class MyModel(db.Model):
__tablename__ = 'my_table'
id = db.Column(db.Integer, primary_key=True)
...
I want to create a base model class so I will be able to declare my models like this:
class MyBase(db.Model):
pass
class MyModel(MyBase):
__tablename__ = 'my_table'
id = db.Column(db.Integer, primary_key=True)
...
Is it possible?
I'm getting the following error:
InvalidRequestError: Class <class 'api.models.base.base_model.BaseModel'> does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class.
I would want to be able to put the tablename and all the column attributes inside my model and not inside my base class.
python sqlalchemy flask-sqlalchemy
I'm using flask-sqlalchemy.
I currently declare my models using:
class MyModel(db.Model):
__tablename__ = 'my_table'
id = db.Column(db.Integer, primary_key=True)
...
I want to create a base model class so I will be able to declare my models like this:
class MyBase(db.Model):
pass
class MyModel(MyBase):
__tablename__ = 'my_table'
id = db.Column(db.Integer, primary_key=True)
...
Is it possible?
I'm getting the following error:
InvalidRequestError: Class <class 'api.models.base.base_model.BaseModel'> does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class.
I would want to be able to put the tablename and all the column attributes inside my model and not inside my base class.
python sqlalchemy flask-sqlalchemy
python sqlalchemy flask-sqlalchemy
edited Mar 26 at 6:38
Ilja Everilä
27.7k5 gold badges40 silver badges68 bronze badges
27.7k5 gold badges40 silver badges68 bronze badges
asked Aug 25 '15 at 16:57
stefanobaldostefanobaldo
6862 gold badges11 silver badges29 bronze badges
6862 gold badges11 silver badges29 bronze badges
What is the purpose of an empty base class?MyBase = db.Model
would seem to work just as well.
– chepner
Aug 25 '15 at 17:08
The base class will not be empty, I was just trying to give an example of what I was trying to do. I will add functionality to it of course.
– stefanobaldo
Aug 25 '15 at 18:03
add a comment |
What is the purpose of an empty base class?MyBase = db.Model
would seem to work just as well.
– chepner
Aug 25 '15 at 17:08
The base class will not be empty, I was just trying to give an example of what I was trying to do. I will add functionality to it of course.
– stefanobaldo
Aug 25 '15 at 18:03
What is the purpose of an empty base class?
MyBase = db.Model
would seem to work just as well.– chepner
Aug 25 '15 at 17:08
What is the purpose of an empty base class?
MyBase = db.Model
would seem to work just as well.– chepner
Aug 25 '15 at 17:08
The base class will not be empty, I was just trying to give an example of what I was trying to do. I will add functionality to it of course.
– stefanobaldo
Aug 25 '15 at 18:03
The base class will not be empty, I was just trying to give an example of what I was trying to do. I will add functionality to it of course.
– stefanobaldo
Aug 25 '15 at 18:03
add a comment |
1 Answer
1
active
oldest
votes
Since your custom base model is not a real model, you need to tell SQLAlchemy that it is abstract by setting __abstract__ = True
on the class.
class MyBase(db.Model):
__abstract__ = True
Unless you are adding common functionality to this custom base, there's no point in doing this. The empty custom base is basically equivalent to just inheriting from db.Model
directly.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32209846%2fcreate-a-base-model-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since your custom base model is not a real model, you need to tell SQLAlchemy that it is abstract by setting __abstract__ = True
on the class.
class MyBase(db.Model):
__abstract__ = True
Unless you are adding common functionality to this custom base, there's no point in doing this. The empty custom base is basically equivalent to just inheriting from db.Model
directly.
add a comment |
Since your custom base model is not a real model, you need to tell SQLAlchemy that it is abstract by setting __abstract__ = True
on the class.
class MyBase(db.Model):
__abstract__ = True
Unless you are adding common functionality to this custom base, there's no point in doing this. The empty custom base is basically equivalent to just inheriting from db.Model
directly.
add a comment |
Since your custom base model is not a real model, you need to tell SQLAlchemy that it is abstract by setting __abstract__ = True
on the class.
class MyBase(db.Model):
__abstract__ = True
Unless you are adding common functionality to this custom base, there's no point in doing this. The empty custom base is basically equivalent to just inheriting from db.Model
directly.
Since your custom base model is not a real model, you need to tell SQLAlchemy that it is abstract by setting __abstract__ = True
on the class.
class MyBase(db.Model):
__abstract__ = True
Unless you are adding common functionality to this custom base, there's no point in doing this. The empty custom base is basically equivalent to just inheriting from db.Model
directly.
answered Aug 25 '15 at 17:11
davidismdavidism
69.6k13 gold badges203 silver badges205 bronze badges
69.6k13 gold badges203 silver badges205 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32209846%2fcreate-a-base-model-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is the purpose of an empty base class?
MyBase = db.Model
would seem to work just as well.– chepner
Aug 25 '15 at 17:08
The base class will not be empty, I was just trying to give an example of what I was trying to do. I will add functionality to it of course.
– stefanobaldo
Aug 25 '15 at 18:03