SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'applicants' (SQL: alter table students add constraint students_app_id_foreign foreign key (app_id) references applicants (Applicant_id) on delete cascade) i get this error when i run migrate or migrate:fresh in cmd
and he are the two tables
public function up()
{
Schema::create('students', function (Blueprint $table) {
$table->increments('Student_id');
$table->unsignedInteger('app_id');
$table->string('name');
$table->string('phone');
$table->char('email');
$table->string('faculty');
$table->timestamps();
$table->foreign('app_id')
->references('Applicant_id')
->on('applicants')
->onDelete('cascade');
});
}
public function up()
{
Schema::create('applicants', function (Blueprint $table) {
$table->increments('Applicant_id');
$table->string('name');
$table->string('Highschooltype');
$table->float('Grade');
$table->integer('National_ID');
$table->char('email');
$table->string('Highschool country');
$table->string('Birth country');
$table->string('faculty');
$table->date('Date of birth');
$table->binary('Image');
$table->binary('Certificate');
$table->binary('Birth Certificate');
$table->timestamps();
});
}
what could be causing the error?
ok so i created the tables all over again but now i am getting this error SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'hostels' already exists (SQL: create table hostels (Hostel_id int unsigned not null auto_increment primary key, ha_id int unsigned not null, Duration varchar(191) not null, Number of rooms int not null, Available rooms int not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
Nothing to do with the current question, you probably have a "mess" with your migrations. Delete (put in a backup directory) the migration file for hotels.
You misunderstand, a rollback does not delete all tables but only the last migration(s).
Never mind, if you did a "fresh" and have delete all you tables, the pb with "hôtels"means you have probably 2 migrations for these table. Review all your migration files, delete the duplicate(s) and then redo migrate.
even when i run migrate:fresh i get this SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') on delete cascade' at line 1 (SQL: alter table hostels add constraint hostels_ha_id_foreign foreign key (ha_id) references hostel_applicants () on delete cascade)
Please make it simple, don't mix your question, remove your migration from hostels and go ahead to close the initial question. Then if you, still have a pb with 'hostels' , you'll open a new question.