trishnag
trishnag

Reputation: 322

SQLALCHEMY set default False nullable True

I have read few SQLAlchemy answers here, but I am still not clear about two scenarios.

What are exactly meant by these and what is the difference between these?

I am having confusing thoughts.

EDIT:

Here is the logic I am trying to implementing.

class Checking(Base):
    __tablename __ = 'Test'
    check=Column(Boolean, nullable=True)
    def __init__(self, check):
        self.check = check
    def test(self):
        if self.check:
            print("Success")
        else:
            print("Failed")

It is always working when check is becoming False i.e, printing 'Failed' but not working when check is becoming True. It is failing there.
The same is happening when the column is set to default=False.

If I set the column to default=True it is working when the column is becoming True but failing when column is becoming False--means vice-versa of the above.

PS: This is not the actual code but it is similar to the actual one that I am trying to achieve.

Upvotes: 4

Views: 9607

Answers (1)

Jesse Bakker
Jesse Bakker

Reputation: 2623

default specifies what the default value for a column is when it is left empty, so default=True only makes sense for Boolean columns and will insert True if the column is empty.

nullable specifies if the value in the column can be NULL (or in python None) (which it will be if it is empty, without specifying the default).

Upvotes: 4

Related Questions