-
wbgill
- Posts: 4
- Joined: Thu Sep 04, 2008 9:11 pm
[Solved] Column Types do not match?
I am new to base and I guess it shows! I am trying to create a simple database to help the non-profit Kiwanis club that I belong to track sales for a fund raiser, keep a customer list and create labels for sending out confirmations after they send their checks to us.
I am setting up the following tables: Customers, Members, Orders, Order Details and Products. I thought I was on the right course, but when trying to set up the relationships, I get the following message «Column types do not match in statement [ALTER TABLES «Orders» ADD FOREIGN KEY («Members») REFERENCES «Members» (MemberID»)].
I am frankly at a loss. I thought that perhaps it was referring to field type and I tried changing from numeric to integer for my «ID» numbers, but got a different error message when I tried to save it. Ended up having to delete the table and create it again.
I would appreciate some help if anyone has any ideas. I’m sure it’s something simple, but darned if I can see what I’m doing wrong.
Thank you!
Bill
Last edited by wbgill on Mon Jun 15, 2009 10:36 pm, edited 1 time in total.
OOo 2.2.X on Ms Windows XP
-
r4zoli
- Volunteer
- Posts: 2882
- Joined: Mon Nov 19, 2007 8:23 pm
- Location: Budapest, Hungary
Re: Column Types do not match?
Post
by r4zoli » Sat Jun 13, 2009 12:42 pm
«Column types do not match in statement [ALTER TABLES «Orders» ADD FOREIGN KEY («Members») REFERENCES «Members» (MemberID»)
Two fields(colums) type must be same when you creating FK relationship.
«MemberID» in referenced table and «Memebers» in table where you want to connect the other table, must be the same type, for example both must be «Integer» type.
-
wbgill
- Posts: 4
- Joined: Thu Sep 04, 2008 9:11 pm
Re: Column Types do not match?
Post
by wbgill » Mon Jun 15, 2009 10:35 pm
Thanks for your response!
I thought that might have been the problem. I did change to integers on all of the ID fields. Think I had numeric to start with, but when I went to relationships I kept getting the error message. This morning when I opened the file, I checked to make sure that the columns were the same and when I opened the relationships page it all worked fine. I have no idea what I did wrong, but ultimately it is working and I appreciate your help. I will be more aware of that in the future.
Thanks again,
Bill
OOo 2.2.X on Ms Windows XP
Автор Syzygy, 10 мая 2010, 13:33
0 Пользователи и 1 гость просматривают эту тему.
При работе с Base заметил, что очень много системных сообщений об ошибках никак не переведено. Пример на скрине (ошибка организации связи между таблицами).
Считаю, что первую часть ошибки, т.е. слова Column types do not match in statement треба перевести. Так как такая ситуация повсеместно, закралась мысль — может, это специально сделано?
Кто что думает?
[вложение удалено Администратором]
A Matter of Life and Death
надо смотреть исходные файлы. Наверное, лучше всего это сделать во время работы над переводом ООо 3.3
Это сообщения HSQLDB. Например, я перевел непереведеные сообщения об ошибках в Postgres, и они появляются на великомогучем. В Base лучше ничего не переводить. Иначе начинается катавасия с терминами.
Согласен!
Если уж очень хочется, можно составить справочник толкований сообщений. Впоследствии из этого справочника можно будет попытаться сделать терминологически согласованный перевод. Но это не скоро.
Собственно, почему тогда в других модулях сообщения об ошибках переведены? Ведь ошибка содержит текст, к примеру, «Первичный ключ не установлен». Почему его нельзя перевести? В чём может быть путаница?
A Matter of Life and Death
Потому что это сообщеие ООО.
Не преведены сообщения, выдаваемые HSQLDB.
Путаницы с сообщением про первичный ключ может и не быть. А вот путаницы, например с обработкой SQLCODE или проверки тригером могут быть и бывают.
Кроме того переводить своства контроов, например, глупо, потому что потом приходится долго втыкать. что имели ввиду переводчики, при работе с англоязычными ресурсами. Те части, которые доступны (используются преимущественно) специалистам, вообще лучше не переводить, чтобы не запутывать терминологию. Кроме того в русском языке все-таки принят контекстный перевод, а не тупой подстрочник. OnBeforeUpdate и OnUpdate свойство как переведете? А переведено как переведено.
Цитата: BigAndy от 22 мая 2010, 17:05Потому что это сообщеие ООО.Не преведены сообщения, выдаваемые HSQLDB.
Это понял, спасибо.
Цитата: BigAndy от 22 мая 2010, 17:05OnBeforeUpdate и OnUpdate свойство как переведете?
Про это никто и не спорит. Я именно про текстовую часть сообщения, которая сообщает, что «Типы столбцов не совпадают [Тут не переведённая инфа про эти столбцы ].
A Matter of Life and Death
I get this error when I try to generate data for my database:
Column name or number of supplied values does not match table definition
This is the structure of my database:
Create database Newsagents;
USE Newsagents;
CREATE TABLE Client (
ClientID int NOT NULL,
Name char(30) NOT NULL,
City char(20) DEFAULT NULL,
Type VARCHAR(15) NOT NULL CHECK (type IN('Individual', 'Company'))
PRIMARY KEY (ClientID)
) ;
CREATE TABLE Product (
ProductNumber char(10) NOT NULL,
ProductName char(20) NOT NULL,
Price float NOT NULL,
isAvailable tinyint NOT NULL,
PRIMARY KEY (ProductNumber)
) ;
CREATE TABLE Sales (
ID INT NOT NULL ,
ClientID INT REFERENCES Client(ClientID),
ProductNumber CHAR(10) REFERENCES Product(ProductNumber),
Quantity INT NOT NULL,
Price FLOAT NOT NULL ,
Date TIMESTAMP NOT NULL,
PRIMARY KEY ( ID )
);
ALTER TABLE sales ADD CONSTRAINT d CHECK (Date > CURRENT_TIMESTAMP);
ALTER TABLE sales ADD CONSTRAINT i CHECK (Quantity > 0);
I than fill my database with some values for Client and Product and I want to generate Sales (using values from Client and Product). This is how I do it:
DECLARE @counter INT
DECLARE @quantity int
DECLARE @prodNum varchar(20)
SET @counter = 0
WHILE @counter < 10
BEGIN
SET @quantity = (select FLOOR(RAND()*100))
SET @prodNum = (select TOP 1 ProductNumber from Product Order by NEWID())
insert into Sales values(
(select TOP 1 ClientID from Client Order by NEWID()),
(select @prodNum),
(select @quantity),
((select @quantity)*(select TOP 1 Price from Product where ProductNumber = @prodNum)),
DEFAULT
)
SET @counter = @counter + 1
END
However I get the Column name or number of supplied values does not match table definition.
What am I doing wrong?
I get this error when I try to generate data for my database:
Column name or number of supplied values does not match table definition
This is the structure of my database:
Create database Newsagents;
USE Newsagents;
CREATE TABLE Client (
ClientID int NOT NULL,
Name char(30) NOT NULL,
City char(20) DEFAULT NULL,
Type VARCHAR(15) NOT NULL CHECK (type IN('Individual', 'Company'))
PRIMARY KEY (ClientID)
) ;
CREATE TABLE Product (
ProductNumber char(10) NOT NULL,
ProductName char(20) NOT NULL,
Price float NOT NULL,
isAvailable tinyint NOT NULL,
PRIMARY KEY (ProductNumber)
) ;
CREATE TABLE Sales (
ID INT NOT NULL ,
ClientID INT REFERENCES Client(ClientID),
ProductNumber CHAR(10) REFERENCES Product(ProductNumber),
Quantity INT NOT NULL,
Price FLOAT NOT NULL ,
Date TIMESTAMP NOT NULL,
PRIMARY KEY ( ID )
);
ALTER TABLE sales ADD CONSTRAINT d CHECK (Date > CURRENT_TIMESTAMP);
ALTER TABLE sales ADD CONSTRAINT i CHECK (Quantity > 0);
I than fill my database with some values for Client and Product and I want to generate Sales (using values from Client and Product). This is how I do it:
DECLARE @counter INT
DECLARE @quantity int
DECLARE @prodNum varchar(20)
SET @counter = 0
WHILE @counter < 10
BEGIN
SET @quantity = (select FLOOR(RAND()*100))
SET @prodNum = (select TOP 1 ProductNumber from Product Order by NEWID())
insert into Sales values(
(select TOP 1 ClientID from Client Order by NEWID()),
(select @prodNum),
(select @quantity),
((select @quantity)*(select TOP 1 Price from Product where ProductNumber = @prodNum)),
DEFAULT
)
SET @counter = @counter + 1
END
However I get the Column name or number of supplied values does not match table definition.
What am I doing wrong?
Description
alvarezp2000
2005-03-17 21:46:36 UTC
I'm trying to add a column as primary key with the following steps: 1. Open the table for Edit. 2. Select a blank row (the next one available). 3. Type "ID" as the field name (tried ID2 also, didn't work). 4. Field type: INTEGER. 5. Right click in the column bar at the left and chose Primary Key. 6. Save the table. I got the following message: --- Error connecting to the data source Column constraints are not acceptable in statement [ALTER TABLE "t_impresoras" ADD "ID" INTEGER NOT NULL] ---
Comment 2
alvarezp2000
2005-04-22 17:36:59 UTC
Ok, I'm trying to do that with a new database... Looks like it doesn't always happen. I'm noticing that it only happens when the table already has data in it.
Comment 3
christoph.lukasiak
2005-04-25 13:05:36 UTC
change owner
Comment 5
alvarezp2000
2005-04-25 21:08:15 UTC
It still happens on m95, which is the latest I can download. You must try it in a database that has some data in it. 1. Open the db. 2. Create a table. Put a PK and a field in it. Save it. Close it. 3. Put some data in the table in both fields. (I need only 1 row to reproduce it). 4. Reopen for edition. Drop the PK, the entire PK field. Save, close. 5. Reopen for edition. Add PK field again (as PK). 6. On saving, you get the message. I noticed that if instead I do this: 5. Reopen for edition. Add PK field again (as normal field). 6. Save. <----- Here I don't get the message. 7. Reopen for edition. 8. Set PK field as PK. 9. Save. <----- First I get a message "Warning, the column 'id' cannot be changed. Should the column instead be deleted and the new format applied?" 10. Click "Yes". 11. There again the message is.
Comment 6
christoph.lukasiak
2005-04-26 09:54:34 UTC
clu->alvarezp2000: now we have it - the problem is the pk field (drop and create) - this is a known problem that should be solved with fix of issue 47321 thx *** This issue has been marked as a duplicate of 47321 ***
Comment 7
christoph.lukasiak
2005-04-26 09:56:20 UTC
close
Comment 8
bencoman
2005-07-31 05:43:45 UTC
Just downloaded OpenOffice today 2005-07-31. Help > About shows version 1.9.118. This use case relates to issue 45338, which was marked as a duplicate of issue 47321, which was closed on 2005-06-29 saying it should be "in the current master". From the date in Release Notes footer "1.9.m118_snapshot.html,v 1.2 2005/07/18" I'm guessing I should have the fix, but I'm not sure how 47321's target milestone of OOo 2.0.1 relates to when the fix is actually released, the the m118 release ntoes dont mention 47321. Anyhow, the use case for 1.9.118..... + Start > OpenOffice.org 1.9.118 > OpenOffice Base + Create New Database <Next> + Leave defaults ticked: Yes, register the database for me; Open the database for editing <Finish> + Filename="New Database" <Save> + <Create Table in Design View> + Add field ( f1, Text [VARCHAR] ) + <Save> TableName="Table1" <OK> + ?Should a primary key be created now? <Yes> > save appears to be successful + Add field ( f2, Integer [INTEGER] ), with AutoValue=Yes + Click out of field on next row. + <Save> >> dialog appears "Error while connecting to the data source. Column constraints are not acceptable in statement [ALTER TABLE "Table1" ADD "f2" INTEGER IDENTITY] This comment has been added to both issues 45338 and 47321. Platform: Windows XP SP2 logged on as Administrator This is my first contribution - please be gentle :)
Не добавляется foreing key.
Проверил столбцы на null,таблицы пустые,типы подходят,длина тоже
Уже не знаю что делать,завтра курсовая.
Пытаюсь связать prepodName(child) с pr_Fam(parent)
Вот дочерняя таблица
SHOW CREATE TABLE catec.group
CREATE TABLE `group` (
`idGroup` int(11) NOT NULL AUTO_INCREMENT,
`Group_Name` varchar(50) DEFAULT NULL,
`qualif_Kod` int(11) DEFAULT NULL,
`prepodName` varchar(100) DEFAULT NULL COMMENT 'Имя препода-куратораn',
PRIMARY KEY (`idGroup`),
KEY `fk_qKod_idx` (`qualif_Kod`),
CONSTRAINT `fk_qKod` FOREIGN KEY (`qualif_Kod`) REFERENCES `qualif` (`qualif_Kod`) ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8
Вот родительская таблица
SHOW CREATE TABLE catec.prepod
CREATE TABLE `prepod` (
`id_prepod` int(11) NOT NULL AUTO_INCREMENT,
`pr_fam` varchar(100) NOT NULL DEFAULT '',
`pr_name` varchar(100) DEFAULT NULL,
`pr_otch` varchar(100) DEFAULT NULL,
`pr_IIN` bigint(12) DEFAULT NULL,
`pr_gender` char(1) DEFAULT NULL,
`pr_DR` date DEFAULT NULL,
`pr_Email` varchar(100) DEFAULT NULL,
`pr_YazObuch` varchar(100) DEFAULT NULL,
`pr_Grajd` varchar(100) DEFAULT NULL,
`pr_Kateg` varchar(100) DEFAULT NULL,
`pr_Natsiya` varchar(100) DEFAULT NULL,
`pr_Tel` varchar(20) DEFAULT NULL,
`pr_SubName` varchar(100) DEFAULT NULL,
`pr_Kurat` char(3) DEFAULT NULL COMMENT 'Кураторство:Да,Нетn',
PRIMARY KEY (`id_prepod`,`pr_fam`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COMMENT='для преподавателей'
Вот и результат
Executing:
ALTER TABLE `catec`.`group`
ADD INDEX `fk_prepod_Fam_idx` (`prepodName` ASC);
ALTER TABLE `catec`.`group`
ADD CONSTRAINT `fk_prepod_Fam`
FOREIGN KEY (`prepodName`)
REFERENCES `catec`.`prepod` (`pr_fam`)
ON DELETE SET NULL
ON UPDATE CASCADE;
Operation failed: There was an error while applying the SQL script to the database.
ERROR 1215: Cannot add foreign key constraint
SQL Statement:
ALTER TABLE `catec`.`group`
ADD CONSTRAINT `fk_prepod_Fam`
FOREIGN KEY (`prepodName`)
REFERENCES `catec`.`prepod` (`pr_fam`)
ON DELETE SET NULL
ON UPDATE CASCADE
Также,при команде SHOW engine InnoDB status
выдает следующее:
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
I’m trying to create a foreign key in mysql workbench, but keep getting this error:
I’ve checked the columns on both tables, and they match up as well as I can make them. One is CHAR(21) not null primary key, and the other is CHAR(21) not null.
Edit (again): (both tables)
First, the original table that I’m trying to link to:
CREATE TABLE IF NOT EXISTS `db`.`Employee` (
`employeeId` CHAR(21) NOT NULL,
`departmentId` CHAR(21) NULL DEFAULT NULL,
`chatStatusId` CHAR(21) NOT NULL DEFAULT 'd15a558946afbbd4a6046',
`employeeNum` INT(4) NOT NULL,
`payrollNum` INT(11) UNSIGNED NULL DEFAULT '0',
`title` VARCHAR(50) NULL DEFAULT NULL,
`dateHired` DATE NOT NULL,
`terminationDate` DATE NULL DEFAULT NULL,
`LastLogin` DATETIME NULL DEFAULT NULL,
`rightMask` INT(11) NOT NULL COMMENT 'we should be using the right table instead',
`teamId` INT(11) UNSIGNED NULL DEFAULT NULL COMMENT 'this is no longer really used',
`IsTeamLead` TINYINT(4) NOT NULL DEFAULT '0',
`bioId` INT(11) UNSIGNED NULL DEFAULT NULL,
`emailSignature` TEXT NULL DEFAULT NULL,
`notes` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`employeeId`),
UNIQUE INDEX `employeeNum` (`employeeNum` ASC),
INDEX `departmentId` (`departmentId` ASC),
INDEX `chatStatusId` (`chatStatusId` ASC),
INDEX `teamId` (`teamId` ASC),
CONSTRAINT `Employee_ibfk_1`
FOREIGN KEY (`employeeId`)
REFERENCES `db`.`Person` (`personId`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `Employee_ibfk_10`
FOREIGN KEY (`teamId`)
REFERENCES `db`.`HaloTeam` (`teamId`)
ON DELETE RESTRICT
ON UPDATE RESTRICT,
CONSTRAINT `Employee_ibfk_8`
FOREIGN KEY (`departmentId`)
REFERENCES `db`.`Department` (`departmentId`),
CONSTRAINT `Employee_ibfk_9`
FOREIGN KEY (`chatStatusId`)
REFERENCES `db`.`ChatStatus` (`chatStatusId`)
ON DELETE RESTRICT
ON UPDATE RESTRICT)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_general_ci
And this is the new table I’m trying to create a foreign key on to the original table:
CREATE TABLE IF NOT EXISTS `db`.`ArticleNote` (
`ArticleNoteID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`ArticleID` INT(10) UNSIGNED NOT NULL,
`Created` TIMESTAMP NOT NULL,
`employeeId` CHAR(21) NOT NULL,
`Note` VARCHAR(255) NOT NULL,
PRIMARY KEY (`ArticleNoteID`),
INDEX `fk_ANote_Article_idx` (`ArticleID` ASC),
INDEX `fk_ANote_Employee_idx` (`employeeId` ASC),
CONSTRAINT `fk_ANote_Article`
FOREIGN KEY (`ArticleID`)
REFERENCES `db`.`Article` (`ArticleID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_ANote_Employee`
FOREIGN KEY ()
REFERENCES `db`.`Employee` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_general_ci
And this is an example of a table that already has a foreign key (using the same column) as the one I’m trying to create in my new table:
CREATE TABLE IF NOT EXISTS `db`.`Article` (
`ArticleID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`ArticleCategoryID` INT(10) UNSIGNED NOT NULL DEFAULT 1,
`Url` VARCHAR(120) NOT NULL,
`Title` VARCHAR(60) NOT NULL,
`Summary` VARCHAR(255) NOT NULL,
`Image` VARCHAR(200) NULL,
`StatusIDE` INT(11) NOT NULL,
`AreaIDE` INT(11) NULL,
`CreatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`CreatedBy` CHAR(21) NULL DEFAULT NULL,
`ExpiresAt` TIMESTAMP NULL DEFAULT NULL,
`PayoutAmount` DECIMAL(11,2) NOT NULL DEFAULT 0.00,
PRIMARY KEY (`ArticleID`),
INDEX `fk_Aritcle_Category_idx` (`ArticleCategoryID` ASC),
INDEX `fk_Article_Status_idx` (`StatusIDE` ASC),
INDEX `fk_Article_Area_idx` (`AreaIDE` ASC),
INDEX `fk_Article_Employee1_idx` (`CreatedBy` ASC),
CONSTRAINT `fk_Article_Employee1`
FOREIGN KEY (`CreatedBy`)
REFERENCES `db`.`Employee` (`employeeId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Article_ArtCat1`
FOREIGN KEY (`ArticleCategoryID`)
REFERENCES `db`.`ArticleCategory` (`ArticleCategoryID`)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT `fk_Article_Status`
FOREIGN KEY (`StatusIDE`)
REFERENCES `db`.`DatabaseEnum` (`DatabaseEnumID`)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT `fk_Article_Area`
FOREIGN KEY (`AreaIDE`)
REFERENCES `db`.`DatabaseEnum` (`DatabaseEnumID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_general_ci