当前位置:网站首页>mysql ”Invalid use of null value“ 解决方法
mysql ”Invalid use of null value“ 解决方法
2022-07-07 11:48:00 【全栈程序员站长】
1.问题描述
因为要更改”information”表中的”编号”列为非空,使用数据库查询语句“alter table information modify ‘编号’ varchar(255) not null”可以更改其他的列,但只是在编号列出错,错误信息为Invalid use of NULL value。
很是奇怪,其他列使用该命令可以查,为什么仅有编号列无法查。
2.错误原因
出现该错误的原因可能是因为已存在的数据的‘编号’列为null,与not null的设置冲突。(查到的原因)。
我自己认为是因为在刚开始新建数据表时,将该列的表结构已经设置,在后续进行更改的时候会因为与之前的设置有冲突(至于为什么这里更改时不能更改,我也没太理解),因为之前我在新建表的时候将编号列的结构属性设置了。
鉴于无法设置为非空,所以通过新建列并设置好not null,便可以成功。
3.解决办法
1)添加新列,设置列的结构属性。
alter table information add column ‘yyy’ varchar(255) not null first; -新添加列yyy至第一列.
2)将出错的列内容复制到新列中并删除出错列
update information set yyy=’编号’; —将’编号’列的所有值复制到yyy列.
alter table information drop ‘编号’; —删除出错的列.
3)修改新列名为出错的列名
alter table information change ‘yyy’ ‘编号’ varchar(255) not null;
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113291.html原文链接:https://javaforall.cn
边栏推荐
- Help tenants
- [1] ROS2基础知识-操作命令总结版
- 实现IP地址归属地显示功能、号码归属地查询
- Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
- Summary of import, export, backup and recovery of mongodb
- 2022-7-6 beginner redis (I) download, install and run redis under Linux
- Distributed transaction solution
- Detr introduction
- Build a secure and trusted computing platform based on Kunpeng's native security
- Ways to improve the performance of raspberry pie
猜你喜欢
MySQL error 28 and solution
cmake 学习使用笔记(一)
2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array
室内ROS机器人导航调试记录(膨胀半径的选取经验)
Introduce six open source protocols in detail (instructions for programmers)
How to make join run faster?
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
Flink | multi stream conversion
flask session伪造之hctf admin
Use of polarscatter function in MATLAB
随机推荐
[daily training] 648 Word replacement
Leecode3. Longest substring without repeated characters
Help tenants
存储过程的介绍与基本使用
move base参数解析及经验总结
DID登陆-MetaMask
Oracle advanced (V) schema solution
Mongodb replication (replica set) summary
Final review notes of single chip microcomputer principle
Realbasicvsr test pictures and videos
Thread pool reject policy best practices
【日常训练--腾讯精选50】231. 2 的幂
如何让join跑得更快?
LeetCode_ Binary search_ Medium_ 153. Find the minimum value in the rotation sort array
PHP - laravel cache
Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
Mathématiques avancées - - chapitre 8 différenciation des fonctions multivariables 1
Simple and easy-to-use code specification
What are the principles for distinguishing the security objectives and implementation methods that cloud computing security expansion requires to focus on?