oh, also I see you attached six separate scripts. Someone here might want to 
help you with that but usually people here don't have the resources to debug 
your whole application, you normally need to take the steps to isolate your 
problem down to a small, single file example that produces the message quickly.

For example, I can reproduce your error just like this:


from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class DealTermRateOptions(Base):
 __tablename__ = 'deal_term_rate_options'

 id = Column(Integer, primary_key=True)

 # this should be "deal.deal_id", not "deal.deal.deal_id"
 deal_id = Column(ForeignKey("deal.deal.deal_id"))


class Deal(Base):
 __tablename__ = 'deal'

 deal_id = Column(Integer, primary_key=True)

e = create_engine("sqlite://", echo=True)
Base.metadata.create_all(e) # <-- will cause the error you are seeing





On Sat, Aug 3, 2019, at 11:35 PM, Mike Bayer wrote:
> 
> 
> On Sat, Aug 3, 2019, at 12:37 PM, Abhishek Sharma wrote:
>> I am using SQLALCHEMY Version 1.2.17
>> 
>> I am using declarative approach to define models, One of my declarative 
>> table definition not available in metadata even i attached the table with 
>> metadata so when other table which is in same metadata is trying to create 
>> relationship with that table it throws the below error:
>> 
>> NoReferencedTableError(u"Foreign key associated with column 
>> 'deal_term_rate_options.deal_id' could not find table 'deal.deal' with which 
>> to generate a foreign key to target column 'deal_id'",)
>> 
>> Attaching the required files for reference.
>> 
>> deal_db is db connection
>> >>> from fni_django_sorcery.db import databases
>> >>> deal_db = databases.get("Deal")
>> >>> deal_db
>> <SQLAlchemy 
>> engine=oracle+cx_oracle://dtadm:***@DT20DB_ORA?allow_twophase=False&coerce_to_decimal=False&optimize_limits=True&use_binds_for_limits=False>
>> >>> deal_db.metadata
>> MetaData(bind=None)
>> >>> deal_db.metadata.tables
>> immutabledict({})
>> 
>> I don't see any error on console also.
> 
> a MetaData collection is empty until you put some Table objects into it. This 
> is usually done by declaring them explicitly either through the Core API 
> (https://docs.sqlalchemy.org/en/13/core/metadata.html) or through the ORM 
> (https://docs.sqlalchemy.org/en/13/orm/mapping_styles.html#declarative-mapping
>  ) . Alternatively you can read Table objects from the database automatically 
> using reflection (https://docs.sqlalchemy.org/en/13/core/reflection.html ).
> 
> The code above doesn't show what you are doing to produce the error, however 
> the error means you've used a ForeignKey() object with the argument 
> "deal.deal.deal_id" and there is no Table object in the metadata with that 
> schema / table combination. "deal.deal.deal_id" means the schema is 
> explicitly set to "deal" and the table name is "deal". It is unlikely that 
> you want to be setting the "deal" schema name explicitly unless "deal" is a 
> different schema from the one you are working within and you have Table 
> objects that set "schema="deal"" explicitly.
> 
> 
> 
> 
>> 
>> Any help will be appreciated.
>> 
>> 
>> 

>> --
>> SQLAlchemy - 
>> The Python SQL Toolkit and Object Relational Mapper
>> 
>> http://www.sqlalchemy.org/
>> 
>> To post example code, please provide an MCVE: Minimal, Complete, and 
>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
>> description.
>> --- 
>> 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 sqlalchemy+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sqlalchemy/f6cd9899-2f0a-47fc-860f-1740fc4e2ddd%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/sqlalchemy/f6cd9899-2f0a-47fc-860f-1740fc4e2ddd%40googlegroups.com?utm_medium=email&utm_source=footer>.
>> 
>> 
>> *Attachments:*
>>  * basemodel.py
>>  * deal.py
>>  * declarative.py
>>  * metadata.py
>>  * termrateoptions.py
> 
> 

> --
>  SQLAlchemy - 
>  The Python SQL Toolkit and Object Relational Mapper
> 
> http://www.sqlalchemy.org/
> 
>  To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
>  --- 
>  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 sqlalchemy+unsubscr...@googlegroups.com.
>  To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/15afc854-5d2c-4949-8cfd-f9aa3f59d7ce%40www.fastmail.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/15afc854-5d2c-4949-8cfd-f9aa3f59d7ce%40www.fastmail.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/381385b3-fc3c-44de-8156-61da6f1c06fa%40www.fastmail.com.

Reply via email to