java - Error with foreign key -
i'm having problems creating mysql table within java program. can't create table... errno: 150
here code:
string url="jdbc:mysql://192.168.1.128:3306"; connection con=(connection) drivermanager.getconnection(url,user,pass); statement stmt=(statement) con.createstatement(resultset.type_scroll_sensitive, resultset.concur_updatable); statement stmt1=(statement) con.createstatement(resultset.type_scroll_sensitive, resultset.concur_updatable); string mysql_new_table=("create table if not exists dbtest.t_ajpes_tr " + "(" + "row_count int primary key auto_increment," + "rn char(15),sspre char(5),reg char(5),eno varchar(10),davcna varchar(15),ime varchar(75),priimek varchar(75),log_id int,index l_id (log_id),foreign key(log_id) references t_ajpes_tr_log(id_log) on delete cascade on update cascade) engine = innodb;"); string mysql_log = ("create table if not exists dbtest.t_ajpes_tr_log" + "(id_log int primary key auto_increment, date_import varchar(45),file_import varchar(75)) engine = innodb;"); stmt.executeupdate(mysql_new_table); stmt1.executeupdate(mysql_log); resultset uprs=stmt.executequery("select * dbtest.t_ajpes_tr"); resultset uprs1=stmt1.executequery("select * dbtest.t_ajpes_tr_log");
i googled many tutorials creating foreign key , still have problems. i'm doing wrong?
you've got issue foreign key constraints, see http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html more details.
first 1 check whether log_id reference t_ajpes_tr_log(id_log) correct
Comments
Post a Comment