Tag Archives: laravel

[Solved] PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long;

php artisan migrate Run Error:
PDOException:: (“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes”)

Solution:
Add the following codes in the file of app/Providers/AppSeviceProvider.php:
use Illuminate\Support\Facades\Schema;
Add in the method of foot:
Schema::defaultStringLength(191);

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
		Schema::defaultStringLength(191);
    }
}

After the prompt
pdoexception:: (“sqlstate [42s01]: base table or view already exists: 1050 table ‘users’ already exists”)
, delete the user table and re-run PHP artist migrate

Laravel5.5 Error: SQLSTATE[42000] Syntax error or access violation 1071 Specified key was too long; max k

Laravel5.5 Configuration Background management Package Voyager problem: SQLSTATE[42000]: Syntax Error or Access Restriction: 1071 Specified key was too long; max key length is 1000 bytes
I heard voyager is good. I’ve tried to create a new file.
D:\wamp64\WWW\laravel\myproject
lambda > PHP artisan voyager: install – with – dummy

Setting up the hooks

Hooks are now ready to use! Go ahead and try to "php artisan hook:install test-hook"
Publishing the Voyager assets, database, language, and config files
Copied Directory [\vendor\tcg\voyager\publishable\assets] To [\public\vendor\tcg\voyager\assets]
Copied Directory [\vendor\tcg\voyager\publishable\database\migrations] To [\database\migrations]
Copied Directory [\vendor\tcg\voyager\publishable\database\seeds] To [\database\seeds]
Copied Directory [\vendor\tcg\voyager\publishable\demo_content] To [\storage\app\public]
Copied Directory [\vendor\tcg\voyager\publishable\lang] To [\resources\lang]
Publishing complete.
Publishing complete.
Migrating the database tables into your application
Migration table created successfully.

 [Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table users add unique users_email_unique(email))

  [Doctrine\DBAL\Driver\PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

  [PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

The problem is too big, according to the official laravel document, change the file of Laravel 5.5 (../app/will/appServiceProvider. PHP) content, below

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema; //Import Schema


class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191); //Solved by increasing StringLength
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

D: \wamp64\www\laravel\myproject


Setting up the hooks
Hooks are now ready to use! Go ahead and try to "php artisan hook:install test-hook"
Publishing the Voyager assets, database, language, and config files
Copied Directory [\vendor\tcg\voyager\publishable\assets] To [\public\vendor\tcg\voyager\assets]
Copied Directory [\vendor\tcg\voyager\publishable\database\migrations] To [\database\migrations]
Copied Directory [\vendor\tcg\voyager\publishable\database\seeds] To [\database\seeds]
Copied Directory [\vendor\tcg\voyager\publishable\demo_content] To [\storage\app\public]
Copied Directory [\vendor\tcg\voyager\publishable\lang] To [\resources\lang]
Publishing complete.
Publishing complete.
Migrating the database tables into your application
Migration table created successfully.

  [Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `translations` add unique `translations_table_name_column_nam
  e_foreign_key_locale_unique`(`table_name`, `column_name`, `foreign_key`, `locale`))

  [Doctrine\DBAL\Driver\PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

  [PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

The database shows that users and Migration imported successfully, while others failed. Finally, I went to Github to find the solution
https://github.com/the-control-group/voyager/issues/901#issuecomment-291470960

1. Update the "config/database.php" for 'mysql'
'engine' => null,
with
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
++++++++++++++++++++++++++++++++++++++++++++

2. Update the "app/Providers/AppServiceProvider.php" with
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        // Specified key was too long error, Laravel News post:
        Schema::defaultStringLength(191);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
++++++++++++++++++++++++++++++++++++++++++++

3. Execute Command:
php artisan cache:clear
php artisan config:clear
php artisan voyager:install --with-dummy
Now, everything works! :)

Has a similar problem here: https://github.com/the-control-group/voyager/issues/1333
Make some changes as described above, and then install
D:\wamp64\www\laravel\myproject
Lambda & gt; PHP artisan voyager: install – with – dummy


Setting up the hooks
Hooks are now ready to use! Go ahead and try to "php artisan hook:install test-hook"
Publishing the Voyager assets, database, language, and config files
Copied Directory [\vendor\tcg\voyager\publishable\assets] To [\public\vendor\tcg\voyager\assets]
Copied Directory [\vendor\tcg\voyager\publishable\database\migrations] To [\database\migrations]
Copied Directory [\vendor\tcg\voyager\publishable\database\seeds] To [\database\seeds]
Copied Directory [\vendor\tcg\voyager\publishable\demo_content] To [\storage\app\public]
Copied Directory [\vendor\tcg\voyager\publishable\lang] To [\resources\lang]
Publishing complete.
Publishing complete.
Migrating the database tables into your application
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table
Migrating: 2016_01_01_000000_add_voyager_user_fields
Migrated:  2016_01_01_000000_add_voyager_user_fields
Migrating: 2016_01_01_000000_create_data_types_table
Migrated:  2016_01_01_000000_create_data_types_table
Migrating: 2016_01_01_000000_create_pages_table
Migrated:  2016_01_01_000000_create_pages_table
Migrating: 2016_01_01_000000_create_posts_table
Migrated:  2016_01_01_000000_create_posts_table
Migrating: 2016_02_15_204651_create_categories_table
Migrated:  2016_02_15_204651_create_categories_table
Migrating: 2016_05_19_173453_create_menu_table
Migrated:  2016_05_19_173453_create_menu_table
Migrating: 2016_10_21_190000_create_roles_table
Migrated:  2016_10_21_190000_create_roles_table
Migrating: 2016_10_21_190000_create_settings_table
Migrated:  2016_10_21_190000_create_settings_table
Migrating: 2016_11_30_135954_create_permission_table
Migrated:  2016_11_30_135954_create_permission_table
Migrating: 2016_11_30_141208_create_permission_role_table
Migrated:  2016_11_30_141208_create_permission_role_table
Migrating: 2016_12_26_201236_data_types__add__server_side
Migrated:  2016_12_26_201236_data_types__add__server_side
Migrating: 2017_01_13_000000_add_route_to_menu_items_table
Migrated:  2017_01_13_000000_add_route_to_menu_items_table
Migrating: 2017_01_14_005015_create_translations_table
Migrated:  2017_01_14_005015_create_translations_table
Migrating: 2017_01_15_000000_add_permission_group_id_to_permissions_table
Migrated:  2017_01_15_000000_add_permission_group_id_to_permissions_table
Migrating: 2017_01_15_000000_create_permission_groups_table
Migrated:  2017_01_15_000000_create_permission_groups_table
Migrating: 2017_01_15_000000_make_table_name_nullable_in_permissions_table
Migrated:  2017_01_15_000000_make_table_name_nullable_in_permissions_table
Migrating: 2017_03_06_000000_add_controller_to_data_types_table
Migrated:  2017_03_06_000000_add_controller_to_data_types_table
Migrating: 2017_04_11_000000_alter_post_nullable_fields_table
Migrated:  2017_04_11_000000_alter_post_nullable_fields_table
Migrating: 2017_04_21_000000_add_order_to_data_rows_table
Migrated:  2017_04_21_000000_add_order_to_data_rows_table
Migrating: 2017_07_05_210000_add_policyname_to_data_types_table
Migrated:  2017_07_05_210000_add_policyname_to_data_types_table
Migrating: 2017_08_05_000000_add_group_to_settings_table
Migrated:  2017_08_05_000000_add_group_to_settings_table
Attempting to set Voyager User model as parent to App\User
Dumping the autoloaded files and reloading all new files
Adding Voyager routes to routes/web.php
Seeding data into the database
Adding the storage symlink to your public folder
The [public/storage] directory has been linked.
Successfully installed Voyager! Enjoy

Success!
Analysis: The key is this:

'engine' => 'InnoDB ROW_FORMAT=DYNAMIC'

This means that the MySQL storage engine USES InnoDB(instead of MyISAM), dynamic text format. Of course InnoDB is not without its disadvantages, you can further study this.

Laravel 500 server error, perfect solution

After installing the Laravel project, open the Laravel for the first time

Solutions:
1. Open the configuration file laravel/config/app.php

3. Find ‘debug’ set to true

4. Run exception: No Application Encryption key has been specified.

5. Find.env. Example under Laravel, make a copy and rename it as “.env”

6. Execute the command: PHP Artisan Key: Generate under Laravel, then refresh the page
 

Perfect solution!

An error is reported in the compiler require of laravel: installation failed, reversing/ composer.json to its original content.

1, preface

when I checked the laravel document, I saw that laravel Passport implements API authentication, which is really good. However, when I actually installed it locally, I could not install it all the time, and the error message was described in the title, which was very annoying. Now I will record the solution process and solution.

, resolution process

error reporting begins at the first step of installing Passport;

composer require laravel/passport

about Passport : http://laravelacademy.org/post/8298.html

1, composer version is not enough?

is suspected to be a problem with my own local composer version, so I decided to update it:

composer self-update 

upgrades Composer itself to the latest version, just run self-update command. It will replace your composer. Phar file to the latest version. Attempt to install failed after update.

2, is the downloaded version too high?

composer require laravel/passport (安装最新版本)
composer require laravel/passport ~4.0(安装4.0版本)

try with the lower version, as always error.

3, there is no stable version, must be compatible with the development version?

is added at the bottom of the composer. Json file:

 "minimum-stability": "dev" 

this section you can refer to the link: https://www.cnblogs.com/XACOOL/p/5627444.html

will not work even if the development version is compatible.

4, I am using the composer source is wrong, the file is wall?

because after downloading and installing composer, the default is foreign mirror, so the connection speed of foreign websites is very slow, and they may be "walled" or even "non-existent" at any time. Therefore, it is suggested to use the domestic composer source

reference link; https://pkg.phpcomposer.com/

, it still doesn't work to replace it with a domestic source.

Solution

Json is useless in composer. So is it the reason why composer. Lock ?

1, about composer. Lock

use composer to install PHP components and you will find that you have created a composer. Lock file. What does this do?

composer. Lock is the version that records all installed PHP components. If multiple developers need to keep the downloaded version of PHP components to reduce unnecessary trouble, then composer. Lock should be added to version control, such as using git or SVN. Not the other way around. It should be noted that when composer install for component dependency, the composer. Lock file will not be updated unless new components are introduced into composer. Json .

, delete composer. Lock try

    1、把需要引入的包写入composer.json中
    (写入的话,就不需要composer require了,直接composer update 即可。)
    2、删除composer.lock
    3、composer clearcache   清除缓存
    4、composer update  更新依赖(重新生成composer.lock

execute once according to the above scheme, and find that Passport has been successfully installed. It seems that the composer. Lock file has not been updated. Json is not directly modified in composer. Then try updating with composer. It is really a mistake.

4. The second solution (I didn't try it myself) 1. If you manually update the composer. Json file, autoload:

    composer dump-autoload

here refer to the link: https://segmentfault.com/q/1010000006974110
composer autoload document address: https://docs.phpcomposer.com/03-cli.html#dump-autoload
2. Execute the composer update command to update the dependency

composer install and composer update

https://blog.csdn.net/sanbingyutuoniao123/article/details/52025565

Oliver:

depth Composer portal https://www.cnblogs.com/XACOOL/p/5627444.html

as for the second option, I haven't had a chance to try it myself. I just checked some materials and thought it might be ok. We can have a try and progress together!

end