I think your fk needs to read "clients.clientid".  It uses the table name.

On Sunday, May 15, 2016, Aaron Dalton <[email protected]> wrote:

> I am pulling my hair out here! I just wasted an hour trying to get this to
> work. I already have one set of models working fine. I simply created a new
> model (a simple two tables) and am suddenly having nothing but trouble! Try
> as I might, I keep getting the following errors:
>
>
>    - sqlalchemy.exc.NoForeignKeysError: Can't find any foreign key
>    relationships between 'clients' and 'clients_redirects'.
>    - sqlalchemy.exc.NoForeignKeysError: Could not determine join
>    condition between parent/child tables on relationship Client.redirects -
>    there are no foreign keys linking these tables.
>
> But the keys are there!! What am I doing wrong?
>
> class Client(Base):
> __tablename__ = 'clients'
>
> clientid = Column(Integer, primary_key=True)
> clientname = Column(String)
> app_id = Column(String)
> app_secret = Column(String)
> description = Column(String)
>
> redirects = relationship("Redirects", back_populates="client")
>
> class Redirects(Base):
> __tablename__ = 'clients_redirects'
>
> id = Column(Integer, primary_key=True)
> clientid = Column(Integer, ForeignKey('client.clientid'))
> URI = Column(String)
>
> client = relationship("Client", back_populates="redirects")
>
> CREATE TABLE `clients` (
>   `clientid` int(10) unsigned NOT NULL AUTO_INCREMENT,
>   `clientname` varchar(255) NOT NULL,
>   `app_id` varchar(64) NOT NULL,
>   `app_secret` varchar(128) NOT NULL,
>   `description` text,
>   PRIMARY KEY (`clientid`),
>   UNIQUE KEY `idx_name` (`clientname`),
>   UNIQUE KEY `idx_appid` (`app_id`),
>   KEY `idx_secret` (`app_secret`),
>   FULLTEXT KEY `idx_description` (`description`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
>
> CREATE TABLE `clients_redirects` (
>   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
>   `clientid` int(10) unsigned NOT NULL,
>   `URI` varchar(255) NOT NULL,
>   PRIMARY KEY (`id`),
>   UNIQUE KEY `idx_uri` (`URI`),
>   KEY `fk_clientid_redirects` (`clientid`),
>   CONSTRAINT `fk_clientid_redirects` FOREIGN KEY (`clientid`) REFERENCES
> `clients` (`clientid`) ON DELETE CASCADE ON UPDATE CASCADE
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <javascript:_e(%7B%7D,'cvml','sqlalchemy%[email protected]');>
> .
> To post to this group, send email to [email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to