PHPMyADMIN - mysql show foreign key constraints #1216 - Magento 2 Database - magento

On localhost i export a magento 2 database using phpmyadmin and try to upload on our server but it giving us error of #1216 - Foreign key constraints. The problem is TABLE A define first in sql and try to create Table B field as Foreign key. So if TABLE B is not creating then giving Foreign key error and not creating database. When i am doing same using command prompt it is working fine. So using phpmyadmin through the error ? Can any one please help me on it?

To solve this use the checkbox Disable Foreign Key Checks when exporting from PhpMyadmin. Or set it yourself:
SET FOREIGN_KEY_CHECKS=0;
and at the end:
SET FOREIGN_KEY_CHECKS=1;

Related

How to use foreignUuid in laravel 9

so im trying to use UUID instead of id in my table
i have two tables, in both, I am using UUID to generate an id. after that, I am trying to use one id as a foreign in the second table.
Im using laravel 9
here my first table
and here is my second table
but when im trying to run php artisan migrate it show this error
i already trying to find on internet but still got nothing
laravel 7 using as uuid foreign key
Foreign key constraint when your primary key is UUID type column
thanks..
thanks, i think i solved it
here's the way, i change my first migration like this
and my second migration

i am trying to create foreign key constraint in laravel 5.8

I can't create a foreign table key:
$table->increments('rt_id');
$table->integer('issued_id')->unsigned();
$table->foreign('issued_id')->references('issue_id')->on('book_issues');
$table->integer('book_id')->unsigned();
$table->foreign('book_id')->references('id')->on('book_details');
I also tried this:
$table->bigIncrements('rt_id');
$table->unsignedBigInteger('issued_id');
$table->foreign('issued_id')->references('issue_id')->on('book_issues');
$table->unsignedBigInteger('book_id');
$table->foreign('book_id')->references('id')->on('book_details');
Looking both of your tables I figured it out that in order to get successful foriegn key... the referenced and referencing fields must have exactly the same data type and options .
So in your case you should remove unsignedBigInteger and unsigned just use integer like this:
$table->integer('issued_id')
Let me know if this worked for you
I just rechecked all the fields and the datatype, i observed that i used increments for primary key and in foreign key i had taken integer('book_id')->unsigned()
And while migrating, i already had the primary table migrated so, i used php artisan migrate:fresh command then this time, it is migrating the foreign table time so, i'm getting the error.
before my foreign key table is been placed first and then the primary key table is placed at last.
So, i changed my model name and replaced according to key constraints as primary table should be stored first in migration folder even sometimes while migrating it doesn't migrates in sequences in ur folder.
So, i used php artisan migrate:fresh
This command is migrating all tables in sequences.

How to get database error when i try to delete a row that has its key like foreign key in another table?

(Laravel framework)
How to create tables in database with migrations so when I try to delete a row from a table that has its key as a foreign key somewhere in another table, I got an error from database not letting me to do that ?
Do I have to create relations in migrations where I say what are the foreign keys in my database, or is there another way using only Laravel models.
I am new with this. Thank you.
You need to remove deactivate the foreign key check so to say, I am using following function to accomplish that. First I set the Foreign key check to 0 then truncate the table and set it back to 1. Setting the foreign key check to 0 allows one to truncate the table even if there are foreign keys.
# functions to truncate users table even if there are foreign key
public static function truncateUserTable()
{
DB::statement('SET FOREIGN_KEY_CHECKS=0');
User::query()->truncate();
DB::statement('SET FOREIGN_KEY_CHECKS=1');
}

Laravel unique foreign key mysql

I have a laravel application with a mysql database
I need to make a unique query, where more than one column in the table is unique with another causing unique rows. I want to include a foreign key in this.
How do I do this?
I have tried doing
$ table -> unique etc but I can't get the foreign key working
I am getting an error saying that the foreign key doesn't exist.
Can anyone please help

Adding an email check constraint in APEX

I'm fairly new to Oracle and very new to APEX. I'm trying to add a constraint on a table to validate the email:
REGEXP_LIKE(CALLER_EMAIL, '[a-zA-Z0-9._%-]+#[a-zA-Z0-9._%-]+\.[a-zA-Z]{2,4}')
Now if I'm right this would work fine inside a CONSTRAINT <name> CHECK(REGEXP_LIKE(...)) however I get this (confusing) error when I attempt to save it:
ORA-00920: invalid relational operator
I think it is because the generated query contains "CALLER_EMAIL":
alter table "CALL" add constraint
"CALL_EMAILFORMAT_CHK" check ( "CALLER_EMAIL" REGEXP_LIKE(CALLER_EMAIL, '[a-zA-Z0-9._%-]+#[a-zA-Z0-9._%-]+\.[a-zA-Z]{2,4}'))
Any ideas?
Try this:
alter table "CALL" add constraint
"CALL_EMAILFORMAT_CHK" check
( REGEXP_LIKE(CALLER_EMAIL, '[a-zA-Z0-9._%-]+#[a-zA-Z0-9._%-]+\.[a-zA-Z]{2,4}'));

Resources