2017-04-07 15:39
浏览 34


there's defenitely something wrong with my Laravel.

I have the Laravel 5.4 installed. I have installed Composer on my windows globally. I have php artisan working, but I'm getting errors everywhere:

php artisan tinker

When I type in php artisan make:model Brand it says Model created succesfully. Awesome, right? When I type in php artisan tinker and App/Brand::all() next, it says Class 'Brand' not found.

While I have Brand.php inside my app folder:


namespace App;

use Illuminate\Database\Eloquent\Model;

class Brand extends Model

By the way, I'm following this series at laracast.


I can't run the mysql command, though I have manually installed mySQL on my windows (globally as well).

It says

'mysql' is not recognized as an internal or external command,
operable program or batch file.


php artisan migrate gives me this error:

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

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

Besides this php artisan migrate is working very well, it creates two tables for me: migrations and users. I thought that was because I have two files in my \database\migrations folder. But...

When I say php artisan make:migration create_brands_table --create=brands, it creates a file inside this folder indeed. Like it should. I add a few lines inside the up() function so it looks like this:

Schema::table('brands', function (Blueprint $table) {

But it does not create a table.

Please note that I did edit my .env file to make a proper database connection, otherwise php artisan migrate would not work on the other two tables I did create with the php artsian migrate command.

It only gives a alreadt exists error. I tried migrate:rollback and migrate:refresh as well. I tried doing this after the composer dump-autoload command, but it came with the same result.

I'm lost in the dark here, I am obviously new to Laravel, but some friends of mine who are familiar with Laravel have never experienced the problems I have.

I have tried to reinstall and create a new project and all... guess what: same results.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dtpn60029
    dtpn60029 2017-04-07 15:42

    You got namespaces wrong, use backslash: App\Brand

    To create a table use Schema::create and not Schema::table

    The mysql part is not Laravel's concern and should not be in this question. Anyway you should check your environment PATH variable.

    点赞 评论
  • duanping1632
    duanping1632 2017-04-07 17:50

    Regarding the already existing table issue, I ran into that before and here's what I've done, first delete your database file, in my case I was using sqlite so my file was database.sqlite, I deleted that and created a new one(don't delete it permanently just in case), run your migrations normally to be sure everything is working for the normal tables, also delete your old Brand migration, then when you are creating a new migration for your Brands table, lose the --create flag,

    Just like this php artisan make:migration create_brands_table, at this point do as mentioned before and use the Schema::create instead of Schema::table, hopefully everything should be working fine now.

    点赞 评论