I cannot change databases column
My Env
MacOS Mojave, MySQL Server version: 10.1.39-MariaDB Source distribution
why
Making a CRUD app, but I want to change table column,
from text to desc, so I searched and used alter
command, but right SQL command returns error messages.
My table
MariaDB [cake_cms]> describe interns;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| email | varchar(255) | NO | | NULL | |
| name | varchar(64) | NO | | NULL | |
| text | varchar(255) | NO | | NULL | |
| location | varchar(64) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
MariaDB [cake_cms]> Alter Table interns Rename Column text to desc;
ERROR 1064 (42000): You have an error in your SQL syntax;
check the manual that corresponds to your MariaDB server version
for the right syntax to use near 'Column text to desc' at line 1
Refered
https://www.dbonline.jp/mysql/table/index18.html
says to use
ALTER TABLE table_name
CHANGE COLUMN old_name TO new_name;
Rename a column in MySQL
This site says:
ALTER TABLE tableName RENAME COLUMN "oldcolname" TO "newcolname" datatype(length);
So I write
alter table interns rename column "name" to "newname" varchar(255);
But returned syntax error message....
I do not know what to do. Please help me!
desc is a sql command so you can't name your table like this
After accidentally running the server using Django 1.10 and possibly run a syncdb/migrate I am getting the following message when I try to access the admin
OperationalError at /admin/
(1054, "Unknown column 'django_content_type.name' in 'field list'")
Request Method: GET
Request URL: http://xx.com:8000/admin/
Django Version: 1.7
Exception Type: OperationalError Exception Value:
(1054, "Unknown column 'django_content_type.name' in 'field list'")
Exception Location: build/bdist.linux-x86_64/egg/MySQLdb/connections.py in defaulterrorhandler, line 36
Python Executable: /tools/python/2.7.3/linux64/bin/python
Python Version: 2.7.3
this seems to be the same issue as the one below:
django admin error - Unknown column 'django_content_type.name' in 'field list'
However when I look at the Django_content_type table I do not see a "name" column.
mysql> show columns from django_content_type;
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| app_label | varchar(100) | NO | MUL | NULL | |
| model | varchar(100) | NO | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
I tried to drop the table but got the following message:
mysql> drop table if exists django_content_type ;
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
I am fairly new to Django and MYSQL and I am at a loss here as to what to do next.
Thanks in advance for your help.
Eric.
what can be the cause?
on the same DB the select statement works as expected:
select id from line where line.id = 298;
but the following delete statement fails:
delete from line where line.id = 298;
with an error:
Unknown column 'line_id' in 'where clause'
output of queries:
mysql> delete from line where line.id = 298;
ERROR 1054 (42S22): Unknown column 'line_id' in 'where clause'
mysql> select id from line where line.id = 298;
+-----+
| id |
+-----+
| 298 |
+-----+
1 row in set (0.00 sec)
mysql> describe line;
+--------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| service_id | int(11) | NO | MUL | NULL | |
| src_site_id | int(11) | NO | MUL | NULL | |
| dest_site_id | int(11) | NO | MUL | NULL | |
+--------------+---------+------+-----+---------+----------------+
4 rows in set (0.01 sec)
SHOW TRIGGERS;
If someone put a trigger without checking it on build (shame on him, that's a really bad thing to do), then it'll fail your query without telling you anything.
It's really tricky, because you can't see directly the error is trigger related, and if you don't use trigger /don't know they are some, the only way is to rebuild the table by yourself after a drop.
try creating an alias of the table you are deleting from:
DELETE FROM line l WHERE l.id = 298
this should work fine
This is a very simple MySQL query.
INSERT INTO users_questions (user_id, question_id, mcopt_id,timestamp)
VALUES (50053, 875, 3092, '2015-08-22 18:01:44');
When I use it I get
ERROR 1054 (42S22): Unknown column 'marks' in 'field list'
marks is a column in the same table whose default value is set to NULL and in the above query I don't even use the column name marks.
So why exactly am i getting the error?
Structure of table:
+-------------+-----------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------+------+-----+-------------------+-------+
| user_id | int(11) | NO | PRI | NULL | |
| question_id | int(11) | NO | PRI | NULL | |
| mcopt_id | int(11) | NO | | NULL | |
| timestamp | timestamp | NO | | CURRENT_TIMESTAMP | |
| marks | int(11) | NO | | NULL | |
+-------------+-----------+------+-----+-------------------+-------+
Just to make it clear I also get the error when I provide the value of marks
INSERT INTO users_questions (user_id, question_id, mcopt_id, timestamp, marks) VALUES (50053, 875, 3094, '2015-08-22 19:15:07', 1)
`
Sometimes, when you implement wrong trigger, it happens.
So just drop your trigger by using:
DROP TRIGGER [IF EXISTS] [schema_name.]trigger_name
and it actually worked in my Mysql case. Maybe helpful for some of you.
A:
create table users_questions2
( user_id int not null,
question_id int not null,
mcopt_id int not null,
timestamp timestamp not null,
marks int not null
);
describe users_questions2;
+-------------+-----------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------+------+-----+-------------------+-----------------------------+
| user_id | int(11) | NO | | NULL | |
| question_id | int(11) | NO | | NULL | |
| mcopt_id | int(11) | NO | | NULL | |
| timestamp | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| marks | int(11) | NO | | NULL | |
+-------------+-----------+------+-----+-------------------+-----------------------------+
INSERT INTO users_questions2 (user_id, question_id, mcopt_id, timestamp) VALUES (50053, 875, 3092, '2015-08-22 18:01:44');
Error Code: 1364. Field 'marks' doesn't have a default value 0.047 sec
INSERT INTO users_questions2 (user_id, question_id, mcopt_id, timestamp,marks) VALUES (50053, 875, 3092, '2015-08-22 18:01:44',1);
-- 1 row(s) affected
INSERT INTO users_questions2 (user_id, question_id, mcopt_id, timestamp,marks) VALUES (50053, 875, 3092, '2015-08-22 18:01:44',null);
Error Code: 1048. Column 'marks' cannot be null 0.000 sec
B:
drop table users_questions2;
create table users_questions2
( user_id int null,
question_id int null,
mcopt_id int null,
timestamp timestamp null,
marks int null
);
describe users_questions2;
+-------------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------+------+-----+---------+-------+
| user_id | int(11) | YES | | NULL | |
| question_id | int(11) | YES | | NULL | |
| mcopt_id | int(11) | YES | | NULL | |
| timestamp | timestamp | YES | | NULL | |
| marks | int(11) | YES | | NULL | |
+-------------+-----------+------+-----+---------+-------+
INSERT INTO users_questions2 (user_id, question_id, mcopt_id, timestamp) VALUES (50053, 875, 3092, '2015-08-22 18:01:44');
1 row(s) affected
So the only way I can get my describe table to look like yours is if they are not null columns (section A above).
Which means your columns do not accept nulls.
Edit:
show variables like "%version%";
+-------------------------+------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------+
| innodb_version | 5.6.24 |
| protocol_version | 10 |
| slave_type_conversions | |
| version | 5.6.24-log |
| version_comment | MySQL Community Server (GPL) |
| version_compile_machine | x86_64 |
| version_compile_os | Win64 |
+-------------------------+------------------------------+
Column marks is defined as not nullable with default value NULL. I suppose that is the problem. You should assign a value in the insert or change default value
The table you are reference in the query does not have a column named marks. First check that you have to correct query which failed and not looking at a different query. Specially when the error message say the table doesn't have a marks column and your query doesn't even have this column written then you are looking at the wrong query. Then check the table you are using and that it has a column named marks. Your error message has nothing to do about NULL or NOT NULL.
I found a similar problem with the command:
INSERT INTO `rel_artsizeprice` (`art_id`, `artsize_id`, `price_tax`) VALUES (1, 3, 2.5);
ERROR 1054 (42S22): Unknown column ' 2.5' in 'field list'
If I delete the space before 2.5, it works:
INSERT INTO `rel_artsizeprice` (`art_id`, `artsize_id`, `price_tax`) VALUES (1, 3,2.5);
Query OK, 1 row affected (0.06 sec)
I a large list of such insert values there are only some places, which generates an error. So I think, that there is an error in the source of the commandline tool (readline or mysql).
I used:
mysql --version
mysql Ver 15.1 Distrib 10.0.26-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
The table You had created will not accept the Null value you have to define the value of marks. It cannot be null probably you have used the not null. if you want your column to be null better use simply null.
One more technical Mistake you are doing here is defining two primary keys. A table should only have one primary key it can have enormous unique keys but primary key should only be one.
You must use single quote marks before and after each record.
INSERT INTO users_questions (user_id, question_id, mcopt_id,timestamp)
VALUES ('50053', '875', '3092', '2015-08-22 18:01:44');
I have this stored procedure:
DROP PROCEDURE IF EXISTS buildMySomething;
CREATE PROCEDURE buildMySomething()
BEGIN
UPDATE current_amount SET current_m_amount = 2 WHERE m_id = 1;
END //
This gives me the following error : ERROR 1054 (42S22): Unknowing column 'current_m_amount' in 'field list'
After looking around on the internet, it is apparent to me that people get this error if the column does not exist, an unexpected character, or simply a syntax error (they have typed the column name wrong)... however... i have checked these possibilities a countless number of times. what am i missing here?
+--------------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+---------+------+-----+---------+----------------+
| m_id | int(11) | NO | PRI | NULL | auto_increment |
| current_m_amount | int(11) | NO | | NULL | |
+--------------------+---------+------+-----+---------+----------------+
I think it might be something to do with the delimiter in use. Try this, which executes on my test server:
DROP PROCEDURE IF EXISTS buildMySomething;
delimiter //
CREATE PROCEDURE buildMySomething()
BEGIN
UPDATE current_amount SET current_m_amount = 2 WHERE m_id = 1;
END //
delimiter ;