I have a migration with $table->datetime('published_at');
and it is already migrated and data is filled in. Now, I have to make this column ->nullable()
, but without using migrate:refresh
or rollback
. How can I achieve this or is it even possible.
Note: No raw sql queries or phpmyadmin. Looking for migration methods.
3
Answers
create new migration and add code below:
or if using mysql:
You can change your table’s structure directly in phpmyadmin
Go to phpmyadmin -> table -> structure
edit publishd_at column and tick null
Simple way is to just run a query like this:
You can create a new migration:
This will generate a new Migration file called
In this migration file, add the following code:
When the command
php artisan migrate
is run, thepublished_at
column will be changed to allownull
. If you need to reverse this,php artisan migrate:refresh
, orphp artisan migrate:reset
, orphp artisan migrate:rollback --step
will change the column back to allownot null
.