antonioribeiro / tracker

Laravel Stats Tracker
MIT License
2.9k stars 596 forks source link

Laravel 5.4 migration problem #249

Open cheebamba opened 7 years ago

cheebamba commented 7 years ago

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 commented 7 years ago

I get the same error. :\

zeroxplorer commented 7 years ago

I get the same issue also.

egyangel commented 7 years ago

same errore Please help

mtaita commented 7 years ago

Have the same issue please help

antonioribeiro commented 7 years ago

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

cheebamba commented 7 years ago

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 commented 7 years ago

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

cheebamba commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

antonioribeiro commented 7 years ago

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 commented 7 years ago

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'

3) 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 commented 7 years ago

`Illuminate\Database\QueryException {#896

sql: "alter table tracker_agents drop index tracker_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_agents drop index tracker_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 commented 7 years ago

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

wnipun commented 7 years ago

Any luck trying to solve this ?

wnipun commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

mtaita commented 7 years ago

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 notifications@github.com 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 .

felipefrancisco commented 7 years ago

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 commented 7 years ago

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 commented 5 years ago

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

$table->dropUnique('tracker_agents_name_unique');

with

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