Please read the documentation first.
https://laravel.com/docs/8.x/migrations#foreign-key-constraints
The foreignId
method is an alias for unsignedBigInteger
while the constrained
method will use conventions to determine the table and column name being referenced. If your table name does not match Laravel's conventions, you may specify the table name by passing it as an argument to the constrained
method:
The issue is that you're providing the table name as 'cascade'
instead of 'users'
.
i.e
//Should be...
$table->foreignId('user_id')->constrained('users');
//Instead of...
$table->foreignId('user_id')->constrained('cascade');
Don't forget to correct the 'category_id'
as well.
If you really wish to apply 'cascade'
options, try:
$table->foreignId('user_id')
->constrained()
->onUpdate('cascade')
->onDelete('cascade');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…