Skip to main content

Posts

Laravel 10 - Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (Connection: mysql, SQL: alter table `users` add unique `users_email_unique`(`email`))

 I got the following error when executing the migration command for the first time.  PS C:\wamp64\www\example-app> php artisan migrate    INFO  Running migrations.   2014_10_12_000000_create_ users_table .............................. .............................. ......... 39ms FAIL    Illuminate\Database\ QueryException   SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (Connection: mysql, SQL: alter table `users` add unique `users_email_unique`(`email`))   at vendor\laravel\framework\src\ Illuminate\Database\ Connection.php:829     825▕                     $this->getName(), $query, $this->prepareBindings($ bindings), $e     826▕                 );     827▕             }     828▕   ➜ 829▕             throw new QueryException(     830▕                 $this->getName(), $query, $this->prepareBindings($ bindings), $e     831▕             );     832▕         }     833▕     }   1   vendor\laravel\framework\src

Change default directory of GitBash in Windows

To see the current default directory . Run this. It will open Explorer in the default directory. $ explorer . Goto GitBash shortcut and right click and select properties. Change the 'Start In' field accordingly. And also remove --cd-to-home from Target location field

PHP Issue - A non-numeric value encountered

This error is encountered when we are going to do addition with different types of variables. See following example $a = ""; $b = 3; try{ $c = $a + $b; }catch(\Exception $e){ var_dump($e->getMessage()); } Exception is occurred. Error is " A non-numeric value encountered " There are two solutions  Solution 1 Change the value of variable $a into zero (0). So, both variables are getting the same type of value now.  $a = 0; $b = 3; try{        $c = $a + $b;         echo $c; }catch(\Exception $e){ var_dump($e->getMessage()); } Solution 2  You can simply cast $a when doing addition $a = ""; $b = 3; try{         $c =  (int) $a  + $b;         echo $c; }catch(\Exception $e){ var_dump($e->getMessage()); } Enjoy..

Simple Email validation regular Expression for Javascript

Following regular expression will validate emails.   var re = /^ [ A-Z0-9a-z \. _+ ] +@ [ A-Za-z0-9 \. - ] + \.([ A-Za-z ]{2,4}) $/ ; re . test ( value ); We will discuss above regular expression part by part. Examples - part1@part2.part3 1. abcd+ef@bbb.com 2. cccc_efg@bbb.lk 3. cccc.efg@bbb.net ^ ==> Start of the expression Part1 [ A-Z0-9a-z \. _+ ] +  ==> There can be many of  A-Z upper case characters, a-z lower case characters, 0-9 numbers, dots and plus signs. @ ==> There must be @ sign after first part of the email Part2 [ A-Za-z0-9 \. - ] + ==> After @ sign there can be same kind of character sets as part 1 (part 2 of email) \. ==> There must be dot character before 3rd part of the email. It should be properly escaped. That is why we use backslash (\) Part3 ([ A-Za-z ]{2,4}) ==> There are must be two to four characters({2,4})including  A-Z upper case characters or a-z lower case characters.  Curly brackets specify the range of characters. So, 2 is minimum num

Mysql Concat() function

Usage 1 SELECT CONCAT("This  ", "is  ", "test ", "concatenation") AS testConcatenation; Syntax concat(exp1, exp2, exp3, ..) - exp1 is required Usage 2 Concat table field and text together SELECT CONCAT(NAME, " is creted at  ", created_at, " ") AS Address FROM province; Enjoy...

Import csv file to MySQL in Windows

LOAD DATA INFILE "C:/Users/USER/Desktop/test.csv" INTO TABLE test COLUMNS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES; Change the file name accordingly.   There may be some issues. 1. SQL Error (1290): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement You need to add LOCAL modifier LOAD DATA statement. Otherwise the following error occurred. So it looks as follows. LOAD DATA LOCAL INFILE "C:/Users/USER/Desktop/test.csv" INTO TABLE test COLUMNS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES; 2. Even if we add LOCAL modifier, there will be another issue as follows. SQL Error (3948): Loading local data is disabled; this must be enabled on both the client and server sides.   3. So you need to enable following SET @ @GLOBAL .local