sql server - Laravel Eloquent how to create UNIQUE constraint with duplicate NULLs -
i'm usinq laravel 5 ms sql server 2014. want create unique constraint should allow multiple null values.
here code i'm using. 'passport_no' has unique if not null.
schema::create('userprofile', function(blueprint $table){ $table->increments('userprofile_id'); $table->integer('user_id')->unsigned(); $table->string('passport_no', 50)->unique()->nullable(); $table->foreign('user_id')->references('id')->on('users') ->onupdate('cascade')->ondelete('cascade'); });
you can use unique index , in filter set condition
passport_no not null
in way can solve problem
Comments
Post a Comment