Solutions for Common Errors on Artisan Commands

by Sam  


As we execute artisan commands, we sometimes encounter these errors. If we’ll not take note of these, we might waste our time looking for solutions. That’s why, I have listed down some of these for you who might be encountering such problems.

1. General error: 1813

Error:

SQLSTATE[HY000]: General error: 1813 Tablespace for table '`lara55db`.`migr
ations`' exists. Please DISCARD the tablespace before IMPORT.

Possible Solution:

Drop the database and create a new one. If you cannot drop it on your phpmyadmin, you have to delete it manually inside the xampp>>mysql>>data folder.

2. 1071 Specified key was too long; max key length is 767 bytes

Error:

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

If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them.

Solution:

Go to App>>Providers>>AppServiceProvider.php and add the script below.

use Illuminate\Support\Facades\Schema;
.
.
public function boot()
{
Schema::defaultStringLength(191);
}

Source

3. Migrating of tables

When you see this error after you executed php artisan migrate,

Error:

[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre
ady exists (SQL: create table `users` (`id` int unsigned not null auto_incr
ement primary key, `username` varchar(255) not null, `email` varchar(255) n
ot null, `password` varchar(255) not null, `created_at` timestamp default 0
not null, `updated_at` timestamp default 0 not null) default character set
utf8 collate utf8_unicode_ci)

you may try these,

Possible solutions

Option 1: From your terminal, execute the command below.

php artisan migrate:rollback

Option 2: Go to your database, drop the migrations and then execute php artisan migrate.

That’s all.

If you’ve encountered errors which have not been written, please comment below for future reference.



Leave a Reply

Your email address will not be published. Required fields are marked *


Need of a Website?

Maybe you're planning to build a landing page for your website. You might also have a plan to create a web application. I can offer you with an affordable but with good quality services. Don't hesitate to submit your specifications by clicking the button below.

Get Quote