in Education by
I am using Laravel 5.7 version. I got the below error for users_activations table while run the command php artisan migrate SQLSTATE[HY000]: General error: 1005 Can't create table auf.#sql-1ecc_fa (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table users_activations add constraint users_activations_user_id_foreign foreign key (user_id) references users (id) on delete cascade) users_activations table Schema::create('users_activations', function (Blueprint $table) { $table->bigIncrements('id'); $table->integer('user_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); // got error for this line $table->string('token'); $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP')); }); user table Schema::create('users', function (Blueprint $table) { $table->bigIncrements('id'); $table->integer('role_id')->default('1'); $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); I have already googling for the error. I have changed $table->integer('user_id')->unsigned(); of users_activations table with $table->unsignedInteger('user_id');. But not worked. Somebody help me please ? Thanks in advance JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The foreign key should be the same type as the id, change your foreign key to bigInteger: $table->bigInteger('user_id')->unsigned();

Related questions

0 votes
    I am using Laravel 5.7 version. I got the below error for users_activations table while run the command ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I'm trying to add foreign key in my table exam: public function up() { Schema::create('exams', ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm pretty new at laravel, in fact and I'm trying to create my very first project. for some ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I am using Laravel Image Intervention to resize an image upload field on my form. This is the error ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I am currently developing a recipe website with Laravel and I have run into an issue on my recipe show ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I am currently developing a recipe website with Laravel and I have run into an issue on my recipe show ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    How can we temporarily disable a foreign key constraint in MySQL?...
asked Feb 1, 2021 in Technology by JackTerrance
0 votes
    I'm trying to populate a database using seeder. I get an error: SQLSTATE[23000]: Integrity constraint ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I have the following models: class Project(models.Model): name = models.CharField(max_length=300, unique= ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I'm using EF code first. By convention, I have added a foreign key and a reference to the foreign ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    Suggestions needed for creating better and efficient search indexes for models having foreign key and many-to-many ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    5. Which key defines a relationship between two tables? (a) Primary key (b) Foreign key (b) Secondary key (d) ... Full form of RDBMS is Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    What is the correct definition of foreign key? The common field of two tables. A field that contains unique data ... of another table. Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    What is the correct definition of foreign key? The common field of two tables. A field that contains unique data ... of another table. Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    In the above DDL command the foreign key entries are got by using the keyword (a) References (b) ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
...