Skip Menu |

This queue is for tickets about the SQL-Translator CPAN distribution.

Report information
The Basics
Id: 70378
Status: resolved
Priority: 0/
Queue: SQL-Translator

People
Owner: Nobody in particular
Requestors: DRBEAN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.11011



Subject: Deploying schema with multi-column foreign key fails with SQLite-3.7.5
With a schema file like: package Bett::Schema::Result::Question __PACKAGE__->table("question"); __PACKAGE__->add_columns( "player", { data_type => "text", is_nullable => 0 }, "lexed", { data_type => "text", is_nullable => 0 }, "league", { data_type => "text", is_nullable => 0 }, "exercise", { data_type => "text", is_nullable => 0 }, "course", { data_type => "text", is_nullable => 0 }, "quoted", { data_type => "text", is_nullable => 0 }, "grammatical", { data_type => "bool", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("lexed", "exercise", "league"); __PACKAGE__->belongs_to( "played_by", "Bett::Schema::Result::Member", { "foreign.player" => "self.player", "foreign.league" => "self.league" }, { is_deferrable => 0, join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE", }, ); And the Member schema: package Bett::Schema::Result::Member; __PACKAGE__->table("member"); __PACKAGE__->add_columns( "league", { data_type => "text", is_foreign_key => 1, is_nullable => 0 }, "player", { data_type => "text", is_foreign_key => 1, is_nullable => 0 }, ); __PACKAGE__->set_primary_key("player", "league"); __PACKAGE__->has_many( "questions", "Bett::Schema::Result::Question", { "foreign.player" => "self.player", "foreign.league" => "self.league" }, { cascade_copy => 0, cascade_delete => 0 }, ); Deploying this, sqlite3 shows the question table schema: Show quoted text
sqlite> .schema question
CREATE TABLE question ( player text NOT NULL, lexed text NOT NULL, league text NOT NULL, exercise text NOT NULL, course text NOT NULL, quoted text NOT NULL, grammatical bool NOT NULL, PRIMARY KEY (lexed, exercise, league), FOREIGN KEY(league) REFERENCES member(league) ); CREATE INDEX question_idx_league_player ON question (league, player); Show quoted text
sqlite>
What happened to the other column, player in the foreign key? [greg@momotaro bett]$ re.pl $ use lib 'lib' $ use Bett::Schema $ use Bett::Model::DB $ my $s = Bett::Schema->connect( Bett::Model::DB->config->{connect_info} ) my ($f_class,$f_class_eclipse_1,$f_class_eclipse_2,$f_class_eclipse_3,$f_class_eclipse_4,$f_class_eclipse_5,$f_class_eclipse_6,$rel,$rel_eclipse_1,$rel_eclipse_2,$rel_eclipse_3,$rel_eclipse_4,$rel_eclipse_5,$rel_eclipse_6); $f_class = 'Bett::Schema::Result::Genre'; $f_class_eclipse_1 = 'Bett::Schema::Result::League'; $f_class_eclipse_2 = 'Bett::Schema::Result::League'; $f_class_eclipse_3 = 'Bett::Schema::Result::Player'; $f_class_eclipse_4 = 'Bett::Schema::Result::Member'; $f_class_eclipse_5 = 'Bett::Schema::Result::Player'; $f_class_eclipse_6 = 'Bett::Schema::Result::Role'; $rel = 'genre'; $rel_eclipse_1 = 'league'; $rel_eclipse_2 = 'league'; $rel_eclipse_3 = 'player'; $rel_eclipse_4 = 'player'; $rel_eclipse_5 = 'player'; $rel_eclipse_6 = 'role'; $Bett_Schema1 = Bett::Schema=HASH(0xb260f68); $ $s->resultset('Question')->create({player=>'V9741065',lexed=>'did rebia die',league=>'GL00005',exercise=>'clay',course=>'YN',quoted=>'Did Rebia die?',grammatical=>1}) Runtime error: DBIx::Class::ResultSet::create(): DBI Exception: DBD::SQLite::db prepare_cached failed: foreign key mismatch [for Statement "INSERT INTO question ( course, exercise, grammatical, league, lexed, player, quoted) VALUES ( ?, ?, ?, ?, ?, ?, ? )"] at (eval 1337) line 6 What foreign key constraint could I be violating here? Isn't it only the one on Member? But, $s->resultset('Member')->find({player=>'V9741065',league=>'GL00005'})->id $VAR1 = 'V9741065'; $VAR2 = 'GL00005';
This is a problem with the SQL::Translator SQLite producer - switching queues. I *believe* there is an outstanding patch in the RT queue (which is sadly rather large). Please look around, if not - some patching will be ncessary. Cheers
Should be resolved in current master after ea4a3ecc5de1c8f062fef3bab51e1cc7a2c23235. Please test and report if successful. Proper release coming in couple weeks. Cheers!
Subject: Re: [rt.cpan.org #70378] Deploying schema with multi-column foreign key fails with SQLite-3.7.5
Date: Wed, 18 Jan 2012 07:53:36 +0000
To: Peter Rabbitson via RT <bug-SQL-Translator [...] rt.cpan.org>
From: Greg Matheson <drbean [...] freeshell.org>
On Tue, 17 Jan 2012, Peter Rabbitson via RT wrote: Show quoted text
That does fix it. See the 2-column foreign key. Show quoted text
sqlite> .schema question
CREATE TABLE 'question' ( 'player' text NOT NULL, 'lexed' text NOT NULL, 'league' text NOT NULL, 'exercise' text NOT NULL, 'course' text NOT NULL, 'quoted' text NOT NULL, 'grammatical' bool NOT NULL, PRIMARY KEY ('lexed', 'exercise', 'league'), FOREIGN KEY ('league', 'player') REFERENCES 'member'('league', 'player') ); CREATE INDEX 'question_idx_league_player' ON 'question' ('league', 'player');
On Wed Jan 18 02:53:45 2012, drbean@freeshell.org wrote: Show quoted text
> On Tue, 17 Jan 2012, Peter Rabbitson via RT wrote: > > > That does fix it. See the 2-column foreign key. >
Sweet. SQLT 0.11010_01 is on cpan if you want to install it, real release soon, pending clean smoketest and some DBIC adjustments (incompatible tests).