Add foreign key on UpgradeSchema return “Foreign key constraint is incorrectly formed”?Foreignkey integrity error while configurable product import magento 2Magento 2 foreign key constraint errorI have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order griderror : add foreign keys in UpgradeSchemaMagento 2 Order Cancel foreign key constraint errorMagento 2 Add new Customer Attribute via UpgradeSchemaForeign key constraint failsError Add Foreign Key Using Install Schema Magento 2Magento 2 : Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint failsMagento 2 : Foreign key constraint is incorrectly formed, ALTER TABLE customer_group
Can a stored procedure reference the database in which it is stored?
How can I wire a 9-position switch so that each position turns on one more LED than the one before?
Where was the County of Thurn und Taxis located?
Creating a chemical industry from a medieval tech level without petroleum
How much cash can I safely carry into the USA and avoid civil forfeiture?
What is the unit of time_lock_delta in LND?
Complex numbers z=-3-4i polar form
Why do distances seem to matter in the Foundation world?
What to do with someone that cheated their way through university and a PhD program?
Restricting the options of a lookup field, based on the value of another lookup field?
A strange hotel
Does a large simulator bay have standard public address announcements?
A Note on N!
Multiple fireplaces in an apartment building?
How much of a wave function must reside inside event horizon for it to be consumed by the black hole?
Are there moral objections to a life motivated purely by money? How to sway a person from this lifestyle?
Contradiction proof for inequality of P and NP?
Nails holding drywall
Co-worker works way more than he should
Does the damage from the Absorb Elements spell apply to your next attack, or to your first attack on your next turn?
What's the difference between using dependency injection with a container and using a service locator?
Double-nominative constructions and “von”
Negative Resistance
Find a stone which is not the lightest one
Add foreign key on UpgradeSchema return “Foreign key constraint is incorrectly formed”?
Foreignkey integrity error while configurable product import magento 2Magento 2 foreign key constraint errorI have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order griderror : add foreign keys in UpgradeSchemaMagento 2 Order Cancel foreign key constraint errorMagento 2 Add new Customer Attribute via UpgradeSchemaForeign key constraint failsError Add Foreign Key Using Install Schema Magento 2Magento 2 : Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint failsMagento 2 : Foreign key constraint is incorrectly formed, ALTER TABLE customer_group
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to add a new attribute to catalog_product_website
table named id_admin_user
to make relation with admin_user
table.
PS: I want to do that to save the ID of the admin user who added a product.
So, I create an UpgradeSchema
with this code
$setup->getConnection()->addColumn(
$setup->getTable('catalog_product_website'),
'id_admin_user',
[
'type' => Table::TYPE_INTEGER,
'size' => null,
'nullable' => false,
'comment' => 'ID ADMIN USER'
]
);
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$setup->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
But when I execute the setup:upgrade
I get this error
SQLSTATE[HY000]: General error: 1005 Can't create table `magento_test`.`#sql-357_165b` (errno: 150 "Foreign key constraint is incorrectly formed")
is there any solution?
magento2 upgradeschema
add a comment |
I want to add a new attribute to catalog_product_website
table named id_admin_user
to make relation with admin_user
table.
PS: I want to do that to save the ID of the admin user who added a product.
So, I create an UpgradeSchema
with this code
$setup->getConnection()->addColumn(
$setup->getTable('catalog_product_website'),
'id_admin_user',
[
'type' => Table::TYPE_INTEGER,
'size' => null,
'nullable' => false,
'comment' => 'ID ADMIN USER'
]
);
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$setup->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
But when I execute the setup:upgrade
I get this error
SQLSTATE[HY000]: General error: 1005 Can't create table `magento_test`.`#sql-357_165b` (errno: 150 "Foreign key constraint is incorrectly formed")
is there any solution?
magento2 upgradeschema
add a comment |
I want to add a new attribute to catalog_product_website
table named id_admin_user
to make relation with admin_user
table.
PS: I want to do that to save the ID of the admin user who added a product.
So, I create an UpgradeSchema
with this code
$setup->getConnection()->addColumn(
$setup->getTable('catalog_product_website'),
'id_admin_user',
[
'type' => Table::TYPE_INTEGER,
'size' => null,
'nullable' => false,
'comment' => 'ID ADMIN USER'
]
);
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$setup->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
But when I execute the setup:upgrade
I get this error
SQLSTATE[HY000]: General error: 1005 Can't create table `magento_test`.`#sql-357_165b` (errno: 150 "Foreign key constraint is incorrectly formed")
is there any solution?
magento2 upgradeschema
I want to add a new attribute to catalog_product_website
table named id_admin_user
to make relation with admin_user
table.
PS: I want to do that to save the ID of the admin user who added a product.
So, I create an UpgradeSchema
with this code
$setup->getConnection()->addColumn(
$setup->getTable('catalog_product_website'),
'id_admin_user',
[
'type' => Table::TYPE_INTEGER,
'size' => null,
'nullable' => false,
'comment' => 'ID ADMIN USER'
]
);
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$setup->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
But when I execute the setup:upgrade
I get this error
SQLSTATE[HY000]: General error: 1005 Can't create table `magento_test`.`#sql-357_165b` (errno: 150 "Foreign key constraint is incorrectly formed")
is there any solution?
magento2 upgradeschema
magento2 upgradeschema
edited 6 hours ago
sayou
asked 6 hours ago
sayousayou
1358
1358
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
In your code, setup should $setup. Check following code:
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$installer->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
[Update]
Try following way:
$setup->getConnection()->addColumn(
$setup->getTable('catalog_product_website'),
'id_admin_user',
[
'type' => Table::TYPE_INTEGER,
'size' => null,
'nullable' => false,
'unsigned' => true,
'comment' => 'ID ADMIN USER'
]
);
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$setup->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
Still getting the same error sir ( I replace$installer
with$setup
)
– sayou
6 hours ago
Check updated answer, working fine with 2.3.
– Sohel Rana
6 hours ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272484%2fadd-foreign-key-on-upgradeschema-return-foreign-key-constraint-is-incorrectly-f%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your code, setup should $setup. Check following code:
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$installer->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
[Update]
Try following way:
$setup->getConnection()->addColumn(
$setup->getTable('catalog_product_website'),
'id_admin_user',
[
'type' => Table::TYPE_INTEGER,
'size' => null,
'nullable' => false,
'unsigned' => true,
'comment' => 'ID ADMIN USER'
]
);
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$setup->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
Still getting the same error sir ( I replace$installer
with$setup
)
– sayou
6 hours ago
Check updated answer, working fine with 2.3.
– Sohel Rana
6 hours ago
add a comment |
In your code, setup should $setup. Check following code:
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$installer->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
[Update]
Try following way:
$setup->getConnection()->addColumn(
$setup->getTable('catalog_product_website'),
'id_admin_user',
[
'type' => Table::TYPE_INTEGER,
'size' => null,
'nullable' => false,
'unsigned' => true,
'comment' => 'ID ADMIN USER'
]
);
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$setup->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
Still getting the same error sir ( I replace$installer
with$setup
)
– sayou
6 hours ago
Check updated answer, working fine with 2.3.
– Sohel Rana
6 hours ago
add a comment |
In your code, setup should $setup. Check following code:
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$installer->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
[Update]
Try following way:
$setup->getConnection()->addColumn(
$setup->getTable('catalog_product_website'),
'id_admin_user',
[
'type' => Table::TYPE_INTEGER,
'size' => null,
'nullable' => false,
'unsigned' => true,
'comment' => 'ID ADMIN USER'
]
);
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$setup->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
In your code, setup should $setup. Check following code:
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$installer->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
[Update]
Try following way:
$setup->getConnection()->addColumn(
$setup->getTable('catalog_product_website'),
'id_admin_user',
[
'type' => Table::TYPE_INTEGER,
'size' => null,
'nullable' => false,
'unsigned' => true,
'comment' => 'ID ADMIN USER'
]
);
$setup->getConnection()->addForeignKey(
$setup->getFkName(
'catalog_product_website',
'id_admin_user',
'admin_user',
'user_id'
),
$setup->getTable('catalog_product_website'),
'id_admin_user',
$setup->getTable('admin_user'),
'user_id',
Table::ACTION_CASCADE
);
edited 6 hours ago
answered 6 hours ago
Sohel RanaSohel Rana
23.6k34461
23.6k34461
Still getting the same error sir ( I replace$installer
with$setup
)
– sayou
6 hours ago
Check updated answer, working fine with 2.3.
– Sohel Rana
6 hours ago
add a comment |
Still getting the same error sir ( I replace$installer
with$setup
)
– sayou
6 hours ago
Check updated answer, working fine with 2.3.
– Sohel Rana
6 hours ago
Still getting the same error sir ( I replace
$installer
with $setup
)– sayou
6 hours ago
Still getting the same error sir ( I replace
$installer
with $setup
)– sayou
6 hours ago
Check updated answer, working fine with 2.3.
– Sohel Rana
6 hours ago
Check updated answer, working fine with 2.3.
– Sohel Rana
6 hours ago
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272484%2fadd-foreign-key-on-upgradeschema-return-foreign-key-constraint-is-incorrectly-f%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown