MariaDB:ALTER TABLE 命令适用于一个 table,但不适用于另一个
MariaDB: ALTER TABLE command works on one table, but not the other
我在 MariaDB 数据库中有两个表(Django 模型):coredb_vsatservicerate
和 coredb_simservicerate
。
MariaDB [servicedbtest]> SHOW CREATE TABLE `coredb_simservicerate`;
+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| coredb_simservicerate | CREATE TABLE `coredb_simservicerate` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(80) NOT NULL,
`service_type` int(11) DEFAULT NULL,
`category` int(11) NOT NULL,
`old` tinyint(1) NOT NULL,
`year` smallint(5) unsigned DEFAULT NULL CHECK (`year` >= 0),
`reseller` tinyint(1) DEFAULT NULL,
`description` longtext NOT NULL,
`description_update_ts` datetime(6) DEFAULT NULL,
`currency` int(11) DEFAULT NULL,
`price` decimal(9,2) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
和
MariaDB [servicedbtest]> SHOW CREATE TABLE `coredb_vsatservicerate`;
+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| coredb_vsatservicerate | CREATE TABLE `coredb_vsatservicerate` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(80) NOT NULL,
`cir_download` int(11) NOT NULL,
`cir_upload` int(11) NOT NULL,
`mir_download` int(11) NOT NULL,
`mir_upload` int(11) NOT NULL,
`price` decimal(7,2) DEFAULT NULL,
`currency` int(11) DEFAULT NULL,
`sector` int(11) DEFAULT NULL,
`coverage_id` int(11) NOT NULL,
`category` int(11) NOT NULL,
`old` tinyint(1) NOT NULL,
`year` smallint(5) unsigned DEFAULT NULL CHECK (`year` >= 0),
`reseller` tinyint(1) DEFAULT NULL,
`bandwidth_id` int(11) DEFAULT NULL,
`description` longtext NOT NULL,
`description_update_ts` datetime(6) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `coredb_vsatservicera_coverage_id_737c0f97_fk_coredb_co` (`coverage_id`),
KEY `coredb_vsatservicera_bandwidth_id_b8943d2d_fk_coredb_da` (`bandwidth_id`),
CONSTRAINT `coredb_vsatservicera_bandwidth_id_b8943d2d_fk_coredb_da` FOREIGN KEY (`bandwidth_id`) REFERENCES `coredb_dataratecombo` (`id`),
CONSTRAINT `coredb_vsatservicera_coverage_id_737c0f97_fk_coredb_co` FOREIGN KEY (`coverage_id`) REFERENCES `coredb_coverage` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.014 sec)
对于 coredb_simservicerate
此命令工作正常:
MariaDB [servicedbtest]> ALTER TABLE `coredb_simservicerate` MODIFY `price` numeric(9, 2) NULL;
Query OK, 0 rows affected (0.001 sec)
Records: 0 Duplicates: 0 Warnings: 0
对于 coredb_vsatservicerate
,此类似命令会引发错误:
MariaDB [servicedbtest]> ALTER TABLE `coredb_vsatservicerate` MODIFY `price` decimal(9, 2) NULL;
ERROR 1054 (42S22): Unknown column '`servicedbtest`.`U0`.`year`' in 'CHECK'
我查看了 MariaDB 的文档,但仍然不知道为什么。
你能帮帮我吗?
这是 MariaDB 中的错误吗?
编辑:
MariaDB [servicedbtest]> show variables like "%version%"
-> ;
+-----------------------------------+------------------------------------------+
| Variable_name | Value |
+-----------------------------------+------------------------------------------+
| in_predicate_conversion_threshold | 1000 |
| innodb_version | 10.3.29 |
| protocol_version | 10 |
| slave_type_conversions | |
| system_versioning_alter_history | ERROR |
| system_versioning_asof | DEFAULT |
| version | 10.3.29-MariaDB-0+deb10u1 |
| version_comment | Debian 10 |
| version_compile_machine | x86_64 |
| version_compile_os | debian-linux-gnu |
| version_malloc_library | system |
| version_source_revision | 4f143a88bcb36e94e9edba8a3c5b4a350dcd9bf9 |
| version_ssl_library | YaSSL 2.4.4 |
| wsrep_patch_version | wsrep_25.24 |
+-----------------------------------+------------------------------------------+
14 rows in set (0.004 sec)
编辑 2:将 DESCRIBE 输出替换为 SHOW CREATE TABLE 输出。
编辑 3: 如果我从 year
中删除检查约束,上述 ALTER TABLE
似乎有效。
MariaDB [servicedbtest]> ALTER TABLE `coredb_vsatservicerate` MODIFY `year` smallint(5) unsigned DEFAULT NULL;
Query OK, 0 rows affected (0.000 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [servicedbtest]> SHOW CREATE TABLE `coredb_vsatservicerate`;
+------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| coredb_vsatservicerate | CREATE TABLE `coredb_vsatservicerate` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(80) NOT NULL,
`cir_download` int(11) NOT NULL,
`cir_upload` int(11) NOT NULL,
`mir_download` int(11) NOT NULL,
`mir_upload` int(11) NOT NULL,
`price` decimal(9,2) DEFAULT NULL,
`currency` int(11) DEFAULT NULL,
`sector` int(11) DEFAULT NULL,
`coverage_id` int(11) NOT NULL,
`category` int(11) NOT NULL,
`old` tinyint(1) NOT NULL,
`year` smallint(5) unsigned DEFAULT NULL,
`reseller` tinyint(1) DEFAULT NULL,
`bandwidth_id` int(11) DEFAULT NULL,
`description` longtext NOT NULL,
`description_update_ts` datetime(6) DEFAULT NULL,
`internal_comment` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `coredb_vsatservicera_coverage_id_737c0f97_fk_coredb_co` (`coverage_id`),
KEY `coredb_vsatservicera_bandwidth_id_b8943d2d_fk_coredb_da` (`bandwidth_id`),
CONSTRAINT `coredb_vsatservicera_bandwidth_id_b8943d2d_fk_coredb_da` FOREIGN KEY (`bandwidth_id`) REFERENCES `coredb_dataratecombo` (`id`),
CONSTRAINT `coredb_vsatservicera_coverage_id_737c0f97_fk_coredb_co` FOREIGN KEY (`coverage_id`) REFERENCES `coredb_coverage` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1424 DEFAULT CHARSET=latin1 |
+------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
MariaDB [servicedbtest]> ALTER TABLE `coredb_vsatservicerate` MODIFY `old` decimal(9, 2) NULL;
Query OK, 374 rows affected (0.090 sec)
Records: 374 Duplicates: 0 Warnings: 0
这是 MariaDB 10.3 中的错误吗?
我使用 MariaDB 10.5 docker-容器 (https://hub.docker.com/r/mariadb/columnstore) 对此进行了测试,但问题并未发生。
这似乎是当前在 Debian-Stable APT 存储库中的版本中的一个 Bug。
升级到 10.5 解决了这个问题。
感谢 Akina 和 Bill Karwin 的帮助
我在 MariaDB 数据库中有两个表(Django 模型):coredb_vsatservicerate
和 coredb_simservicerate
。
MariaDB [servicedbtest]> SHOW CREATE TABLE `coredb_simservicerate`;
+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| coredb_simservicerate | CREATE TABLE `coredb_simservicerate` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(80) NOT NULL,
`service_type` int(11) DEFAULT NULL,
`category` int(11) NOT NULL,
`old` tinyint(1) NOT NULL,
`year` smallint(5) unsigned DEFAULT NULL CHECK (`year` >= 0),
`reseller` tinyint(1) DEFAULT NULL,
`description` longtext NOT NULL,
`description_update_ts` datetime(6) DEFAULT NULL,
`currency` int(11) DEFAULT NULL,
`price` decimal(9,2) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
和
MariaDB [servicedbtest]> SHOW CREATE TABLE `coredb_vsatservicerate`;
+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| coredb_vsatservicerate | CREATE TABLE `coredb_vsatservicerate` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(80) NOT NULL,
`cir_download` int(11) NOT NULL,
`cir_upload` int(11) NOT NULL,
`mir_download` int(11) NOT NULL,
`mir_upload` int(11) NOT NULL,
`price` decimal(7,2) DEFAULT NULL,
`currency` int(11) DEFAULT NULL,
`sector` int(11) DEFAULT NULL,
`coverage_id` int(11) NOT NULL,
`category` int(11) NOT NULL,
`old` tinyint(1) NOT NULL,
`year` smallint(5) unsigned DEFAULT NULL CHECK (`year` >= 0),
`reseller` tinyint(1) DEFAULT NULL,
`bandwidth_id` int(11) DEFAULT NULL,
`description` longtext NOT NULL,
`description_update_ts` datetime(6) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `coredb_vsatservicera_coverage_id_737c0f97_fk_coredb_co` (`coverage_id`),
KEY `coredb_vsatservicera_bandwidth_id_b8943d2d_fk_coredb_da` (`bandwidth_id`),
CONSTRAINT `coredb_vsatservicera_bandwidth_id_b8943d2d_fk_coredb_da` FOREIGN KEY (`bandwidth_id`) REFERENCES `coredb_dataratecombo` (`id`),
CONSTRAINT `coredb_vsatservicera_coverage_id_737c0f97_fk_coredb_co` FOREIGN KEY (`coverage_id`) REFERENCES `coredb_coverage` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.014 sec)
对于 coredb_simservicerate
此命令工作正常:
MariaDB [servicedbtest]> ALTER TABLE `coredb_simservicerate` MODIFY `price` numeric(9, 2) NULL;
Query OK, 0 rows affected (0.001 sec)
Records: 0 Duplicates: 0 Warnings: 0
对于 coredb_vsatservicerate
,此类似命令会引发错误:
MariaDB [servicedbtest]> ALTER TABLE `coredb_vsatservicerate` MODIFY `price` decimal(9, 2) NULL;
ERROR 1054 (42S22): Unknown column '`servicedbtest`.`U0`.`year`' in 'CHECK'
我查看了 MariaDB 的文档,但仍然不知道为什么。
你能帮帮我吗? 这是 MariaDB 中的错误吗?
编辑:
MariaDB [servicedbtest]> show variables like "%version%"
-> ;
+-----------------------------------+------------------------------------------+
| Variable_name | Value |
+-----------------------------------+------------------------------------------+
| in_predicate_conversion_threshold | 1000 |
| innodb_version | 10.3.29 |
| protocol_version | 10 |
| slave_type_conversions | |
| system_versioning_alter_history | ERROR |
| system_versioning_asof | DEFAULT |
| version | 10.3.29-MariaDB-0+deb10u1 |
| version_comment | Debian 10 |
| version_compile_machine | x86_64 |
| version_compile_os | debian-linux-gnu |
| version_malloc_library | system |
| version_source_revision | 4f143a88bcb36e94e9edba8a3c5b4a350dcd9bf9 |
| version_ssl_library | YaSSL 2.4.4 |
| wsrep_patch_version | wsrep_25.24 |
+-----------------------------------+------------------------------------------+
14 rows in set (0.004 sec)
编辑 2:将 DESCRIBE 输出替换为 SHOW CREATE TABLE 输出。
编辑 3: 如果我从 year
中删除检查约束,上述 ALTER TABLE
似乎有效。
MariaDB [servicedbtest]> ALTER TABLE `coredb_vsatservicerate` MODIFY `year` smallint(5) unsigned DEFAULT NULL;
Query OK, 0 rows affected (0.000 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [servicedbtest]> SHOW CREATE TABLE `coredb_vsatservicerate`;
+------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| coredb_vsatservicerate | CREATE TABLE `coredb_vsatservicerate` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(80) NOT NULL,
`cir_download` int(11) NOT NULL,
`cir_upload` int(11) NOT NULL,
`mir_download` int(11) NOT NULL,
`mir_upload` int(11) NOT NULL,
`price` decimal(9,2) DEFAULT NULL,
`currency` int(11) DEFAULT NULL,
`sector` int(11) DEFAULT NULL,
`coverage_id` int(11) NOT NULL,
`category` int(11) NOT NULL,
`old` tinyint(1) NOT NULL,
`year` smallint(5) unsigned DEFAULT NULL,
`reseller` tinyint(1) DEFAULT NULL,
`bandwidth_id` int(11) DEFAULT NULL,
`description` longtext NOT NULL,
`description_update_ts` datetime(6) DEFAULT NULL,
`internal_comment` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `coredb_vsatservicera_coverage_id_737c0f97_fk_coredb_co` (`coverage_id`),
KEY `coredb_vsatservicera_bandwidth_id_b8943d2d_fk_coredb_da` (`bandwidth_id`),
CONSTRAINT `coredb_vsatservicera_bandwidth_id_b8943d2d_fk_coredb_da` FOREIGN KEY (`bandwidth_id`) REFERENCES `coredb_dataratecombo` (`id`),
CONSTRAINT `coredb_vsatservicera_coverage_id_737c0f97_fk_coredb_co` FOREIGN KEY (`coverage_id`) REFERENCES `coredb_coverage` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1424 DEFAULT CHARSET=latin1 |
+------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
MariaDB [servicedbtest]> ALTER TABLE `coredb_vsatservicerate` MODIFY `old` decimal(9, 2) NULL;
Query OK, 374 rows affected (0.090 sec)
Records: 374 Duplicates: 0 Warnings: 0
这是 MariaDB 10.3 中的错误吗?
我使用 MariaDB 10.5 docker-容器 (https://hub.docker.com/r/mariadb/columnstore) 对此进行了测试,但问题并未发生。
这似乎是当前在 Debian-Stable APT 存储库中的版本中的一个 Bug。
升级到 10.5 解决了这个问题。
感谢 Akina 和 Bill Karwin 的帮助