Sunday 15 April 2012

php - how to make a varchar nullable and unique together in mysql (laravel) -


Can I make a MySQL column blank and unique? I have a table that stores email_id to users if the user wants to give it to others, it will be empty (blank). I have read in some other questions that I can create unique fields by default, but when I create a table, I receive this error

  # 1067 - Invalid default value for 'email' (I Only for test purpose)   

The main table is generated with the Larva schema builder class

  $ table-> Text ('email') - & gt; Faucet () - & gt; Unique (); (No default is added)   

In DB

  + -------------- + ----- - ------------ + ------ + ----- + --------- + ------------- - - + | Field | Type | Faucet Key | Default | Extra | + -------------- + ------------------ + ------ + ----- + - - ------ + ---------------- + | Email_id | Varchar (200) | Yes. United Nations Faucet |   

key 'users_email_id_unique' (while entering an email with an empty string)

  duplicate entry 

question now This is how a varchar field is controlled, which is unique and tap together.

I know this is an old question, it is for those who have the same problem is.

You are trying to add a empty string, you have created the column faucet and unique . This means that you are trying something that you should not do you can send multiple blank values, but multiple empty can not be string

  Public function set emaill property ($ value) {if (if empty) on mysql  empty  value  

Consider. ($ Value) {// empty string $ this- & gt; Features ['company'] = NULL; } And {$ this- & gt; Attributes ['company'] = $ value; }}

No comments:

Post a Comment