简体   繁体   English

MySql - 错误代码:1932。引擎中不存在表

[英]MySql - Error Code: 1932. Table doesn't exist in engine

I am getting the error below on a mysql restart after adding an enum field to my existing table.在向现有表中添加枚举字段后,我在重新启动 mysql 时收到以下错误。 Locks table and only a complete database restore fixes issue as I can't drop the table either.锁定表,只有完整的数据库还原才能修复问题,因为我也无法删除该表。

Error Code: 1932. Table 'users' doesn't exist in engine

My table and data is as follows:我的表和数据如下:

CREATE TABLE `users` (
  `id` char(36) NOT NULL,
  `name` varchar(191) NOT NULL,
  `email` varchar(191) NOT NULL,
  `password` varchar(191) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `users_email_unique` (`email`)
);

INSERT INTO `users` VALUES 
(
    '11111111-1111-1111-1111-111111111111',
    'John Doe',
    'user@email.com',
    'password',
    NOW(),
    NOW()
);

Table above works until line below is executed and mysql is restarted.上表一直有效,直到执行下面的行并重新启动 mysql。

ALTER TABLE users ADD `role` enum('test1', 'test2') AFTER `password`

I have also done a diff on the table structure of a before and after.我还对前后的表结构做了一个差异。 Only line with comment gets added and locks the table.仅添加带有注释的行并锁定表。

CREATE TABLE `users2` (
  `id` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `password` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `role` enum('test1','test2') COLLATE utf8mb4_unicode_ci DEFAULT NULL, -- only diff
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `users1_email_unique` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

This is where it gets weird.这就是它变得奇怪的地方。 Line below adds role to the end of the table and doesn't lock the table.下面的行将角色添加到表的末尾并且不锁定表。

ALTER TABLE users ADD `role` enum('test1', 'test2'); -- AFTER `password`

Seems the AFTER is the issue.似乎 AFTER 是问题所在。 Doesn't matter if I try a different position.如果我尝试不同的位置也没关系。

Any suggestions would be appreciated.任何建议,将不胜感激。

You can also assign the default value while adding the column.您还可以在添加列时分配默认值。

ALTER TABLE users ADD `role` enum('test1', 'test2') DEFAULT 'test1' AFTER `password`;

So, NULL values will not allow and all the rows will be assigned with 'test1' .因此,不允许使用 NULL 值,所有行都将分配给'test1'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM