MariaDB [test]> create table users (id bigint unsigned NOT NULL primary key)engine=innodb;
|
Query OK, 0 rows affected (0.025 sec)
|
|
MariaDB [test]> create table `test` (`id` bigint unsigned not null auto_increment primary key, `user_id` bigint unsigned not null, `additionalData` json null, `created_at` timestamp null, `updated_at` timestamp null) engine=innodb default character set utf8mb4 collate 'utf8mb4_unicode_ci';
|
Query OK, 0 rows affected (0.025 sec)
|
|
MariaDB [test]> alter table `test` add constraint `test_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete cascade;
|
Query OK, 0 rows affected (0.127 sec)
|
Records: 0 Duplicates: 0 Warnings: 0
|
|
MariaDB [test]> show create table test;
|
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
| Table | Create Table |
|
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
| test | CREATE TABLE `test` (
|
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
`user_id` bigint(20) unsigned NOT NULL,
|
`additionalData` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`additionalData`)),
|
`created_at` timestamp NULL DEFAULT NULL,
|
`updated_at` timestamp NULL DEFAULT NULL,
|
PRIMARY KEY (`id`),
|
KEY `test_user_id_foreign` (`user_id`),
|
CONSTRAINT `test_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
|
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
1 row in set (0.001 sec)
|
|
MariaDB [test]> select version();
|
+-----------------+
|
| version() |
|
+-----------------+
|
| 10.4.10-MariaDB |
|
+-----------------+
|
1 row in set (0.000 sec)
|