question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Columns are always NotNullable (as a default)

See original GitHub issue

I have the following migration (one of many, and it is a typical ASP.NET Identity table):

Create.Table("aspnet_users")
    .WithColumn("id").AsGuid().PrimaryKey().NotNullable()
    .WithColumn("username").AsString()
    .WithColumn("normalized_username").AsString()
    .WithColumn("email").AsString()
    .WithColumn("normalized_email").AsString()
    .WithColumn("email_confirmed").AsBoolean().NotNullable()
    .WithColumn("password_hash").AsString()
    .WithColumn("security_stamp").AsString()
    .WithColumn("concurrency_stamp").AsString()
    .WithColumn("phone_number").AsString()
    .WithColumn("phone_number_confirmed").AsBoolean().NotNullable()
    .WithColumn("two_factor_enabled").AsBoolean().NotNullable()
    .WithColumn("lockout_end").AsDateTime()
    .WithColumn("lockout_enabled").AsBoolean().NotNullable()
    .WithColumn("access_failed_count").AsInt32().NotNullable()
    .WithColumn("display_name").AsString();

My assumption was that unless NotNullable is specified the column would default to Nullable. However after the migration has ran, all the columns are NotNullable.

I’m using Postgresql. Am I doing something wrong?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jzabroskicommented, Apr 6, 2020

It also seems as though SQL Server lets you change the default behavior of implicit syntax, so FluentMigrator should explicitly specify null or not null. See: SET ANSI_NULL_DFLT_ON:

This setting only affects the nullability of new columns when the nullability of the column is not specified in the CREATE TABLE and ALTER TABLE statements. When SET ANSI_NULL_DFLT_ON is ON, new columns created by using the ALTER TABLE and CREATE TABLE statements allow null values if the nullability status of the column is not explicitly specified. SET ANSI_NULL_DFLT_ON does not affect columns created with an explicit NULL or NOT NULL.

1reaction
jzabroskicommented, Apr 6, 2020

Thanks for offering to help, and it’s wecome. To be quite honest, just answering questions takes a lot of my and @fubar-coder 's time. I don’t think we get enough development time to actually improve things. So picking off some easy tasks would definitely help towards adding features. I feel this will be a good year roadmap wise, as I have finally come up with some decisions around how to support multiple target framework monikers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL Server: why is it possible to set default NULL value on ...
Yes, you can say bit NOT NULL DEFAULT NULL (example). As explained, the purpose is to ensure that if someone tries to avoid...
Read more >
Why you Should Always Specify Whether a Column ...
Look there! NOT NULL constraints on all the columns, even though your connection settings specified that allowing them was the default.
Read more >
Rails/NotNullColumn: Why are defaults required? #237
I'd like to generate some discussion on why this cop is requiring defaults for not-nullable columns. First: $ bundle exec rubocop -V 0.76.0 ......
Read more >
Is there a compelling reason why columns in SQL are ...
No. There is no compelling reason why SQL defaults to nullable. In fact, many prominent researchers in relational database theory have disagreed ...
Read more >
How Default Value and Nullable Column Works?
When a user adds a column with default to a table in SQL Server, which already exists, it always checks the nullable property...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found