0

i'm trying to add a foreign ID column to an existing table. I've done so successfully and all my PHPunit tests pass locally:


  Schema::table('responses', function (Blueprint $table) {
     $table->foreignId('road_id')
                    ->after('id')
                    ->nullable()
                    ->constrained();
     
     $table->string('email')->after('road_id');
  });


I have github actions setup and all the PHPunit tests seem to fail with the Error (both running sqlite):

Cannot add a NOT NULL column with default value NULL (SQL: alter table "responses" add 
column "email" varchar not null)

Im having a hard time debugging this error since everything works locally. Any issues with the approach I took?

EDIT: I've updated my question since i'm now seeing a different error message through my github action. It is in relation to adding an email column to an already existing table. Any reason why this wouldn't be allowed? My current work around was change the email column creation to:

$table->string('email')->nullable()->after('road_id');

And then i created an additional migration that does this:

$table->string('email')->nullable(false)->change();

Now both tests are passing both locally and in my github action. I'm still very unsure as to the big question... why did I have to create that additional migration just to change the column to not nullable in order for my github action to run tests successfully? Any insight is much appreciated.

stacker
  • 233
  • 1
  • 5
  • 14
  • Are you using the same database configuration in your actions, as on local? Ie) both sqlite, or mysql etc.. – Kurt Friars Mar 09 '21 at 04:05
  • yah, a 2 second google for "NOT NULL column with default value NULL" and: https://stackoverflow.com/questions/3170634/cannot-add-a-not-null-column-with-default-value-null-in-sqlite3. I am assuming that you are using SQLite in actions and mysql locally. – Kurt Friars Mar 09 '21 at 04:07
  • Does this answer your question? [Cannot add a NOT NULL column with default value NULL in Sqlite3](https://stackoverflow.com/questions/3170634/cannot-add-a-not-null-column-with-default-value-null-in-sqlite3) – Kurt Friars Mar 09 '21 at 04:08
  • In the links you provided they're trying to add a NOT NULL constraint to the column they are creating (I added ->nullable() to allow null values). I am running both sqlite locally and through my actions. Am still trying to figure out why i had to add the extra migration to fix my issue in my edit above. – stacker Mar 09 '21 at 05:47
  • 1
    https://stackoverflow.com/questions/20822159/laravel-migration-with-sqlite-cannot-add-a-not-null-column-with-default-value-n – Kurt Friars Mar 09 '21 at 06:47
  • That is indeed my issue - Thanks a bunch @KurtFriars – stacker Mar 09 '21 at 15:12

0 Answers0