tracker icon indicating copy to clipboard operation
tracker copied to clipboard

Laravel 5.4 migration problem

Open cheebamba opened this issue 7 years ago • 23 comments

When installing tracker on fresh Laravel 5.4 i get this error:

PHP Fatal error:  Call to a member function getCode() on null in D:\_Instal\xampp\htdocs\cheebamba\vendor\laravel\framework\src\Illuminate\Database\QueryException.php on line 38


  [Symfony\Component\Debug\Exception\FatalErrorException]
  Call to a member function getCode() on null

cheebamba avatar Feb 15 '17 10:02 cheebamba

I get the same error. :\

ghost avatar Feb 16 '17 09:02 ghost

I get the same issue also.

zeroxplorer avatar Feb 17 '17 03:02 zeroxplorer

same errore Please help

egyangel avatar Feb 17 '17 08:02 egyangel

Have the same issue please help

mtaita avatar Feb 21 '17 19:02 mtaita

As said in https://github.com/antonioribeiro/tracker/issues/250, should be fixed now.

antonioribeiro avatar Feb 21 '17 19:02 antonioribeiro

Yes, this error got fixed, but now im getting on newest Laravel and newest xampp and easyphp this error:

[Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'updated_at' (SQL: create table `tracker_paths` (`id` bigint unsigned not null auto_increment primar
  y key, `path` varchar(255) not null, `created_at` timestamp not null, `updated_at` timestamp not null) default character set utf8mb4 collate utf8mb4_unicode_ci engine = InnoDB ROW_FO
  RMAT=DYNAMIC) (SQL: SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'updated_at' (SQL: create table `tracker_paths` (`id` bigint unsigned not null a
  uto_increment primary key, `path` varchar(255) not null, `created_at` timestamp not null, `updated_at` timestamp not null) default character set utf8mb4 collate utf8mb4_unicode_ci en
  gine = InnoDB ROW_FORMAT=DYNAMIC))

[Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'updated_at' (SQL: create table `tracker_paths` (`id` bigint unsigned not null auto_increment primar
  y key, `path` varchar(255) not null, `created_at` timestamp not null, `updated_at` timestamp not null) default character set utf8mb4 collate utf8mb4_unicode_ci engine = InnoDB ROW_FO
  RMAT=DYNAMIC)

[PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'updated_at'

cheebamba avatar Feb 22 '17 11:02 cheebamba

Seems to be related to this issue: https://github.com/laravel/framework/issues/3602

ndberg avatar Feb 22 '17 12:02 ndberg

I was able to get pass this, but then i get error in last migration:

Illuminate\Database\QueryException {#675
  #sql: "alter table `tracker_agents` add unique `tracker_agents_name_unique`(`name`)"
  #bindings: []
  #message: "SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'name' used in key specification without a key length (SQL: alter table `tracker_agents` add unique `
tracker_agents_name_unique`(`name`))"
  #code: "42000"

So i did this migration manually by changing sql to:

alter table tracker_agents add unique tracker_agents_name_unique(name(255))

cheebamba avatar Feb 22 '17 13:02 cheebamba

I'm able to confirm the tracker migrations breaking on Laravel 5.4 install.

It breaks at the point where I'm migrating the tables.

Screenshot as follows.

image

saifulss avatar Feb 22 '17 15:02 saifulss

It's probably related to the changes made to MySQL new uft8 charset.

antonioribeiro avatar Feb 22 '17 20:02 antonioribeiro

For those having SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'updated_at', you have to set strict => false on your database connection:

image

antonioribeiro avatar Feb 22 '17 21:02 antonioribeiro

Posted and answered it on StackOverflow:

This is due to sql mode [STRICT_TRANS_TABLES][1], so you have three options:

  1. Fix your migrations.

  2. Change strict to false in your mysql connection:

    'mysql' => $database = [
    	...
        'strict' => false,
    	...
    ],

Which will disable all those sql modes:

set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
  1. Set custom modes, removing STRICT_TRANS_TABLES
    'mysql' => $database = [
    	...
        'modes' => "set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'",
    	...
    ],

So, we should investigate it and probably do nr 1) on Tracker, right?

antonioribeiro avatar Feb 22 '17 21:02 antonioribeiro

Illuminate\Database\QueryException {#896 #sql: "alter table tracker_agentsdrop indextracker_agents_name_unique" #bindings: [] #message: "SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'tracker_agents_name_unique'; check that column/key exists (SQL: alter table tracker_agentsdrop indextracker_agents_name_unique)" #code: "42000" #file: "/home/nipun/Documents/Projects/cs_web/vendor/laravel/framework/src/Illuminate/Database/Connection.php" #line: 729 -previous: PDOException {#895 #message: "SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'tracker_agents_name_unique'; check that column/key exists" #code: "42000" #file: "/home/nipun/Documents/Projects/cs_web/vendor/laravel/framework/src/Illuminate/Database/Connection.php" #line: 457 +errorInfo: array:3 [ 0 => "42000" 1 => 1091 2 => "Can't DROP 'tracker_agents_name_unique'; check that column/key exists" ] -trace: { 25. PDOStatement->execute() ==> new PDOException(): { src: { /home/nipun/Documents/Projects/cs_web/vendor/laravel/framework/src/Illuminate/Database/Connection.php:457: """ \n return $me->getPdo()->prepare($query)->execute($bindings);\n });\n """ } } 24. Illuminate\Database\Connection->Illuminate\Database\{closure}() ==> PDOStatement->execute(): { src: { /home/nipun/Documents/Projects/cs_web/vendor/laravel/framework/src/Illuminate/Database/Connection.php:457: """ \n return $me->getPdo()->prepare($query)->execute($bindings);\n });\n """ } args: array:1 [ 0 => [] ] } 23. Illuminate\Database\Connection->runQueryCallback() ==> Illuminate\Database\Connection->Illuminate\Database\{closure}(): { src: { /home/nipun/Documents/Projects/cs_web/vendor/laravel/framework/src/Illuminate/Database/Connection.php:722: """ try {\n $result = $callback($this, $query, $bindings);\n }\n """ } args: array:3 [ 0 => Illuminate\Database\MySqlConnection {#907 #pdo: PDO {#899 inTransaction: true attributes: { CASE: NATURAL ERRMODE: EXCEPTION AUTOCOMMIT: 1 PERSISTENT: false DRIVER_NAME: "mysql" SERVER_INFO: "Uptime: 262557 Threads: 6 Questions: 2389 Slow queries: 0 Opens: 721 Flush tables: 1 Open tables: 89 Queries per second avg: 0.009" ORACLE_NULLS: NATURAL CLIENT_VERSION: "mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $" SERVER_VERSION: "5.7.11" STATEMENT_CLASS: array:1 [ 0 => "PDOStatement" ]

Is this the same issue ? I am getting this output when trying to migrate.

and also I am using,

'strict' => false,

Any idea what went wrong ?

wnipun avatar Feb 23 '17 09:02 wnipun

Same as @nipun5perera. Tried it again, fresh pull of the latest Tracker. Set strict to false. Still getting the 42000 error.

saifulss avatar Feb 24 '17 06:02 saifulss

Any luck trying to solve this ?

wnipun avatar Feb 25 '17 12:02 wnipun

I did edit create_tracker_agents_table.php and changed ,

$table->string('name')->unique();

to

$table->string('name',255);

and then added

$table->unique('name');

so my create would look like this,

$table->bigIncrements('id'); $table->string('name',255); $table->string('browser')->index(); $table->string('browser_version'); $table->timestamp('created_at')->index(); $table->timestamp('updated_at')->index(); $table->unique('name');

and then edited fix_agent_name.php and changed

$table->mediumText('name')->unique()->change();

to

$table->string('name',255)->unique()->change();

for me this solved that key length problem and everything migrated successfully.

wnipun avatar Feb 25 '17 13:02 wnipun

Laravel's default $table->timestamps() migration method calls nullable() on created_at and updated_at, so why aren't we doing this when calling timestamp('created_at')->index() ? Why not do this in each of the migrations:


                $table->timestamp('created_at')->nullable()->index();
                $table->timestamp('updated_at')->nullable()->index();

tmaly1980 avatar Feb 28 '17 17:02 tmaly1980

Not sure if this is related, but I am having issues with migrating. When I run php artisan migrate:refresh it removes all my existing tables and only populates with the tracker, reset password, and users tables. I've spent a few hours trying to debug why it only pulls in those tables, but haven't had any luck.

adteague avatar Mar 22 '17 04:03 adteague

I just removed the 'fix_agent_name' migration and everything worked as intented

adteague avatar Mar 22 '17 05:03 adteague

Thanxs for update,

Also have already done the same adn everything is alright now

On Wed, Mar 22, 2017 at 8:22 AM, Austin Teague [email protected] wrote:

I just removed the 'fix_agent_name' migration and everything worked as intented

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/antonioribeiro/tracker/issues/249#issuecomment-288301660, or mute the thread https://github.com/notifications/unsubscribe-auth/ATRlDcZX5akn8OFEiqLFYfjSLlEB8y3mks5roLARgaJpZM4MBj1U .

mtaita avatar Mar 22 '17 10:03 mtaita

Solved it.

  1. Remove 2017_01_31_311101_fix_agent_name.php.
  2. On 2015_03_07_311076_create_tracker_agents_table.php, change line 26 from
$table->string('name')->unique();

to

$table->name('name', 255)->unique();

felipefrancisco avatar Apr 21 '17 15:04 felipefrancisco

Or you could change 2017_01_31_311101_fix_agent_name.php replacing $table->mediumText('name')->unique()->change(); with $table->string('name', 1024)->unique()->change();

lucafregoso avatar Apr 26 '17 15:04 lucafregoso

I used database prefix which was an issue. Solution is replacing

$table->dropUnique('tracker_agents_name_unique');

with

$table->dropUnique(['name']);

bapfnet avatar Oct 19 '19 13:10 bapfnet