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;








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.










share|improve this question
























  • 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

















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.










share|improve this question
























  • 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













0












0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















3














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.






share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    3














    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.






    share|improve this answer



























      3














      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.






      share|improve this answer

























        3












        3








        3







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 25 '15 at 17:11









        davidismdavidism

        69.6k13 gold badges203 silver badges205 bronze badges




        69.6k13 gold badges203 silver badges205 bronze badges


















            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.



















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현