microsoft / PartsUnlimited

.Net Core + SQL Azure app for DevOps Scenarios
https://microsoft.github.io/PartsUnlimited/
MIT License
667 stars 1.53k forks source link

Laravel #208

Open perezmotajavier opened 4 years ago

perezmotajavier commented 4 years ago

Hello friends I cannot migrate I use sqlite and here is the error:

SQL: alter table "posts" add column "category_id" integer not null laravel and here is my table

Migrating: 2019_01_03_124007_add_category_id_to_posts_table Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL (SQL: alter table "posts" add column "category_id" integer not null)

public function up() { Schema::table('posts', function (Blueprint $table) { $table->unsignedInteger('category_id')->after('author_id'); $table->foreign('category_id')->references('id')->on('categories')->onDelete('restrict'); }); } /**

yanshulsharmarepo commented 4 years ago

Give a default Value for category because if you alter a table for foreign key then old raw will take NULL value for that column. and for foreign key this is only possible then reference column (other table) is not primary. because primary key don't have NULL value.