vendredi 29 mars 2019

How to handle this migration error in laravel?

I am working in a restaurant system and I am adding a table to the database and have a problem with create_menus_table I think the problem is in the relations between tables but I can't find it.

I tried to delete all of them and made models again and checked whether the error in the tables or not and delete the database and delete all modules

the error in cmd

**Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 (SQL: alter table menus add constraint menus_user_id_foreign foreign key (user_id) references users ()) at C:\xampp\htdocs\laravelrestaurantapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) {

664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668| Exception trace: 1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1") C:\xampp\htdocs\laravelrestaurantapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:452 2 PDO::prepare("alter table menus add constraint menus_user_id_foreign foreign key (user_id) references users ()") C:\xampp\htdocs\laravelrestaurantapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:452 Please use the argument -v to see more details.**

the menus table

    <?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateMenusTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('menus', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title')->unique();
            $table->string('type');
            $table->text('description');
            $table->boolean('status');
            $table->string('image');
        // to make relation with the users table as the menu has several users
        // as one to many relationship
        $table->integer('user_id')->unsigned();
        $table->foreign('user_id')->reference('id')->on('users');

        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('menus');
}

}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2uzoXYN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire