1

I have a running application, I see a field in a form is not required and can be left empty. but by the migrations, that field in database is set to be "not null". I wanted to to change it so I did it by checking Null. But how I do the same thing with migrations?? I read documentation and created this

public function up()
{
   Scheme::table('modules', function (Blueprint $table) {
       $table->text('content')->nullable();
   });
}

but when I run migration, it give me error table already exists (obviously, because other migration files are there). How should I do it to achieve my target.

ealgehdr
  • 43
  • 12

1 Answers1

0

Change your code to this and notice the ->change() part:

public function up()
{
   Scheme::table('modules', function (Blueprint $table) {
       $table->text('content')->nullable()->change();
   });
}

Documentation on changing columns

NB: You'll need the Doctrine/DBal package in order for this to work:

Before modifying a column, be sure to add the doctrine/dbal dependency to your composer.json file. The Doctrine DBAL library is used to determine the current state of the column and create the SQL queries needed to make the specified adjustments to the column

Douwe de Haan
  • 6,247
  • 1
  • 30
  • 45