Hi, This was previously working when I had default named ids like $table->id();, but I want to now name my primary keys.
I get the following error and am trying to understand the problem with the foreign key mismatch
SQLSTATE[HY000]: General error: 1 foreign key mismatch - "source_sentences" referencing "projects"
(SQL: insert into "source_sentences"
("grouping_index", "page_num", "project_id", "sentence_text", "user_id")
values
(0, 1, 1, qwerty., 1), (1, 1, 1, asdf., 1), (2, 1, 1, zcxv., 1))
when trying to insert data here
DB::table('source_sentences')->insert( $data );
My tables look like this
public function up()
{
Schema::create('projects', function (Blueprint $table) {
$table->id('project_id');
$table->string('title', 500);
$table->string('description', 5000)->nullable();
$table->char('source_lang', 2);
$table->timestamps();
$table->foreignId('user_id')->constrained();
$table->comment('The name and details of the text being translated.');
});
}
and
public function up()
{
Schema::create('source_sentences', function (Blueprint $table) {
$table->id('source_sentence_id');
$table->mediumInteger('grouping_index');
$table->mediumInteger('page_num');
$table->string('sentence_text', 1000);
$table->timestamps();
$table->foreignId('user_id')->constrained();
$table->foreignId('project_id')->constrained();
$table->unique(['project_id', 'grouping_index', 'page_num']);
$table->comment('The original text, broken into sentences.');
});
}
After changing the tables, I ran php artisan migrate:fresh which ran successfully. Anyone know what the problem might be?
Thanks.