Make an existing nullable column non nullable
See original GitHub issuei have an existing column which ive created, The column has some data in it. How do i make it non nullable, still preserving the data.
.table('users', function(table){
table.string('mobile').notNull();
})
This attempts to add a new column.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Altering a Column from Null to Not Null in SQL Server - Chartio
Most critically, all existing NULL values within the column must be updated to a non-null value before the ALTER command can be successfully...
Read more >Altering a column: null to not null - sql server - Stack Overflow
SET MyNullableColumn = 0 only works if your existing column is a numeric column. For non-numeric types you need to set another default...
Read more >Problems with adding NOT NULL columns or making nullable ...
In the first case, you simply add a DEFAULT constraint to the column first, with a value that isn't NULL , and in...
Read more >SQL NOT NULL Constraint - W3Schools
By default, a column can hold NULL values. The NOT NULL constraint enforces a column to NOT accept NULL values. This enforces a...
Read more >SQL SERVER - Altering Column - From NULL to NOT NULL
Step 1: Convert all values to NOT NULL · Step 2: Change Column NULL Values ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For those of you coming here from google, the syntax is:
Converting an existing nonNullable column to be nullable (reverse the up/down if you want a nonNullable to be nullable).
It’s worth mentioning that the
.nullable().alter()methods didn’t work for me because my personal project uses SQLIte and it does not support alter column.Here’s de error message: