Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 5.4 migration problem #249

Open
cheebamba opened this issue Feb 15, 2017 · 23 comments
Open

Laravel 5.4 migration problem #249

cheebamba opened this issue Feb 15, 2017 · 23 comments

Comments

@cheebamba
Copy link

cheebamba commented Feb 15, 2017

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
@ghost
Copy link

ghost commented Feb 16, 2017

I get the same error. :\

@zeroxplorer
Copy link

I get the same issue also.

@egyangel
Copy link

same errore
Please help

@mtaita
Copy link

mtaita commented Feb 21, 2017

Have the same issue please help

@antonioribeiro
Copy link
Owner

As said in #250, should be fixed now.

@cheebamba
Copy link
Author

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'

@ndberg
Copy link
Contributor

ndberg commented Feb 22, 2017

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

@cheebamba
Copy link
Author

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))

@saifulss
Copy link

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

@antonioribeiro
Copy link
Owner

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

@antonioribeiro
Copy link
Owner

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
Copy link
Owner

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?

@wnipun
Copy link

wnipun commented Feb 23, 2017

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 ?

@saifulss
Copy link

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

@wnipun
Copy link

wnipun commented Feb 25, 2017

Any luck trying to solve this ?

@wnipun
Copy link

wnipun commented Feb 25, 2017

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.

@tmaly1980
Copy link

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();

@adteague
Copy link

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
Copy link

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

@mtaita
Copy link

mtaita commented Mar 22, 2017 via email

@felipefrancisco
Copy link

felipefrancisco commented Apr 21, 2017

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();

@lucafregoso
Copy link

lucafregoso commented Apr 26, 2017

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();

@bapfnet
Copy link

bapfnet commented Oct 19, 2019

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

$table->dropUnique('tracker_agents_name_unique');

with

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests