dtoqa66028 2017-04-07 15:39
浏览 36
已采纳

我的Laravel出了点问题

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:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Brand extends Model
{
    //
}

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


mySQL

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.

migrate

php artisan migrate gives me this 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

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) {
    $table->increments('id');
    $table->string('name');
    $table->text('description');
    $table->timestamps();
});

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 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算