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.

6
  • Are you using the same database configuration in your actions, as on local? Ie) both sqlite, or mysql etc.. Commented Mar 9, 2021 at 4:05
  • yah, a 2 second google for "NOT NULL column with default value NULL" and: stackoverflow.com/questions/3170634/…. I am assuming that you are using SQLite in actions and mysql locally. Commented Mar 9, 2021 at 4:07
  • Does this answer your question? Cannot add a NOT NULL column with default value NULL in Sqlite3 Commented Mar 9, 2021 at 4: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. Commented Mar 9, 2021 at 5:47
  • 1
    stackoverflow.com/questions/20822159/… Commented Mar 9, 2021 at 6:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.