0

I'm using Laravel/popular and when I add 3 classes and migrate it gives me error. Here that 3 classes are listed:

JordanMiguel\LaravelPopular\LaravelPopularServiceProvider::class,
Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
Illuminate\Auth\AuthServiceProvider:class,

Laravel popular

In Connection.php line 664:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table visits add unique visits_ip_visitable_id_visitable_type_date_unique(ip, visitable_id, visitable_type, date))

In Connection.php line 458:

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

kalpesh satasiya
  • 799
  • 8
  • 18

2 Answers2

0

In ur app\Providers\AppSErviceProvider.php file add these two lines:

at the top: use Illuminate\Support\Facades\Schema;

inside the boot function:

Schema::defaultStringLength(191);

Updated: After seeing ur comments its not working, u may need to run the below mysql query in your phpmyadmin (if u have access).

CREATE TABLE `visits` (
  `id` int(10) UNSIGNED NOT NULL,
  `ip` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `visitable_id` int(11) NOT NULL,
  `visitable_type` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `date` date NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `visits`
--
ALTER TABLE `visits`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `visits_ip_visitable_id_visitable_type_date_unique` (`ip`,`visitable_id`,`visitable_type`,`date`),
  ADD KEY `visits_ip_index` (`ip`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `visits`
--
ALTER TABLE `visits`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;COMMIT;

This will create the table for you, no need to run php artisan migrate Its not the perfect answer but it solves your problem, temporarily.

arun
  • 4,595
  • 5
  • 19
  • 39
  • I already added it sir @arun kumar –  Jan 30 '18 at 09:04
  • close ur terminal or putty then open again. if it didn't help, run 'composer dump-autoload' – arun Jan 30 '18 at 09:05
  • still same :( . i tried cache:clear , dump-autoload . and still same error –  Jan 30 '18 at 09:07
  • `SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `visits` add unique `visits_ip_visitable_id_visitable_type_d ate_unique`(`ip`, `visitable_id`, `visitable_type`, `date`))` –  Jan 30 '18 at 09:08
  • @М.Билгүүн, take a look at updated answer – arun Jan 30 '18 at 09:21
0

In your AppServiceProvider, add this line to boot method-

public function boot()
{
    Schema::defaultStringLength(191);
}
Sohel0415
  • 9,523
  • 21
  • 30