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 constraintmenus_user_id_foreign
foreign key (user_id
) referencesusers
()) 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 constraintmenus_user_id_foreign
foreign key (user_id
) referencesusers
()") 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');
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire