0

I have a database field that should allow NULL as value but also the values should be unique, the migration line:

$table->string('projet_number')->nullable()->unique();

In mySQL database everything worked fine, somehow NULL was ignore for unique validation. Now I need to migrate my database to Microsoft SQL Server and now this doesn't work anymore because NULL is duplicated:

"message": "SQLSTATE[23000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot insert duplicate key row in object 'dbo.projects' with unique index 'projects_number_unique'. The duplicate key value is ()

This answer describes exactly what I need to to: https://stackoverflow.com/a/767702/3018671

But how I can implement this in Laravel? Also I tried other solutions like this one: https://stackoverflow.com/a/35101246/3018671, But it doesn't work.

NicuVlad
  • 2,491
  • 3
  • 28
  • 47
  • @Larnu, didn't found this one. let me try – NicuVlad May 28 '21 at 09:27
  • @Larnu, works! thank you!!!. I think this question is somehow duplicated. Do you want to submit the answer? – NicuVlad May 28 '21 at 09:42
  • I'll just Gold Badge it, @NicuVlad . I don't know enough (anything) about Laravel to confirm the answer would work, but I was pretty confident it was right from the syntax it was demonstrating. You should upvote the answer you used on the other question too, to show your appreciation. – Thom A May 28 '21 at 09:50

0 Answers0