Im trying to create a replica of a database that has multiple schemas with
SQLite (so i can build a test environment). I build the Result objects and
when i deploy i get an error with the foreign keys. The SQLite CREATE TABLE
instruction does not allow database names in the foreign key clause (if you
remove it, the table creates fine).
Is there a way to work around this issue? Im not overly concerned if the
sqlite database doesn't contain the foreign key relationships.
Thanks
Todd
A full sample of the code.
package MyApp::Schema;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_namespaces();
1;
package MyApp::Schema::Result::A;
use base qw/DBIx::Class::Core/;
__PACKAGE__->table('other_db.A');
__PACKAGE__->add_columns(qw/ a1 a2 /);
__PACKAGE__->set_primary_key('a1');
__PACKAGE__->has_many(bs => 'MyApp::Schema::Result::B', 'b1');
1;
package MyApp::Schema::Result::B;
use base qw/DBIx::Class::Core/;
__PACKAGE__->table('other_db.B');
__PACKAGE__->add_columns(qw/ b1 b2 /);
__PACKAGE__->set_primary_key('b1');
__PACKAGE__->belongs_to(a => 'MyApp::Schema::Result::A', 'b1');
1;
The main script:
use MyApp::Schema;
my $schema = MyApp::Schema->connect('dbi:SQLite:dbname=test.db','','',{});
my $res = $schema->storage->dbh_do(
sub {
my ($storage, $dbh) = @_;
$dbh->do("attach database 'other.db' as other_db");
}
);
$schema->deploy();
The error given is:
DBIx::Class::Schema::deploy(): DBIx::Class::Schema::deploy(): DBI
Exception: DBD::SQLite::db do failed: near ".": syntax error [for Statement
"CREATE TABLE other_db.B (
b1 NOT NULL,
b2 NOT NULL,
PRIMARY KEY (b1),
FOREIGN KEY(b1) REFERENCES other_db.A(a1)
)"] at dbi.pl line 17
(running "CREATE TABLE other_db.B (
b1 NOT NULL,
b2 NOT NULL,
PRIMARY KEY (b1),
FOREIGN KEY(b1) REFERENCES other_db.A(a1)
)") at dbi.pl line 17
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]