Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

514
Views
Laravel 1215 No se puede agregar una restricción de clave externa

Hola, tengo problemas con las migraciones de mi base de datos en mi aplicación laravel.

Este es el error:

 [Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL : alter table `transactions` add constraint `transactions_user_sid_foreign` foreign key (`user_sid`) references `users` (`sid`))

Esta es mi migración de transacciones:

 public function up() { Schema::create('transactions', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('user_sid')->index(); $table->unsignedInteger('store_id')->index(); $table->unsignedInteger('value'); $table->timestamps(); $table->softDeletes(); }); }

Esta es la migración de usuarios:

 public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->unsignedInteger('role_id')->index(); $table->string('sid')->unique(); $table->rememberToken(); $table->timestamps(); $table->softDeletes(); }); }

Y finalmente mis claves foráneas:

 Schema::table('transactions', function (Blueprint $table){ $table->foreign('user_sid')->references('sid')->on('users'); $table->foreign('store_id')->references('id')->on('stores'); });
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No puede agregar una clave externa a una columna con un tipo diferente, así que simplemente cámbiela, por ejemplo, en la tabla de users :

 $table->unsignedInteger('sid')->unique();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!