<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create DB tables with constraints in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-db-tables-with-constraints/m-p/694101#M53829</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"it does not work" ... error? nothing happened?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 May 2017 00:13:02 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2017-05-16T00:13:02Z</dc:date>
    <item>
      <title>Create DB tables with constraints</title>
      <link>https://community.esri.com/t5/python-questions/create-db-tables-with-constraints/m-p/694100#M53828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;Hi All,&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;Short question: How can I create constrains (like primary key and foreign key) amongst enterprise database tables?&amp;nbsp;&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;Detailed description: I know that for file based geodatabase, to achieve constraints or relationships there are RelationshipObjects. But in my case I am using Postgres database for nonspatial tables. Now I want to create primary-foreign key relatioship amongst them. How can I do that?&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;I am using below code which works for file based database but not for the Enterprise databases.&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;ADJUSTIT_DB_CONN = "C:/Users/jbheda.WE-DO-IT/Documents/ArcGIS/Projects/MyProject4/localhost.sde"&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;config = os.path.join(ADJUSTIT_DB_CONN,"config")&lt;BR /&gt;network = os.path.join(ADJUSTIT_DB_CONN,"network")&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;configNetworkRelClass = os.path.join(ADJUSTIT_DB_CONN,"configNetworkRel")&lt;BR /&gt;configLandbaseRelClass = os.path.join(ADJUSTIT_DB_CONN,"configLandbaseRel")&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;env.overwriteOutput = True&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;######### FUNCTIONS ###########&lt;BR /&gt;config_table = arcpy.CreateTable_management(os.path.dirname(config), os.path.basename(config))&lt;BR /&gt;arcpy.AddField_management(config_table, "config_name", "TEXT", field_length=256)&lt;BR /&gt;arcpy.AddField_management(config_table, "user_updated", "TEXT", field_length=64)&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;network_table = arcpy.CreateTable_management(os.path.dirname(network), os.path.basename(network))&lt;BR /&gt;arcpy.AddField_management(network_table, "table_name", "TEXT", field_length=256)&lt;BR /&gt;arcpy.AddField_management(network_table, "config_name", "TEXT", field_length=256)&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;&lt;BR /&gt;# Create simple relationship class between 'config' and 'network'&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;forLabel = "network_list"&lt;BR /&gt;backLabel = "network_config_name"&lt;BR /&gt;primaryKey = "config_name"&lt;BR /&gt;foreignKey = "config_name"&lt;BR /&gt;arcpy.CreateRelationshipClass_management(config,&amp;nbsp;network,&amp;nbsp;configNetworkRelClass,&amp;nbsp;"SIMPLE",&amp;nbsp;forLabel,&amp;nbsp;backLabel,&amp;nbsp;"NONE",&amp;nbsp;"ONE_TO_MANY",&amp;nbsp;"NONE",&amp;nbsp;primaryKey,&amp;nbsp;foreignKey)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 May 2017 23:17:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-db-tables-with-constraints/m-p/694100#M53828</guid>
      <dc:creator>JadavBheda</dc:creator>
      <dc:date>2017-05-15T23:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Create DB tables with constraints</title>
      <link>https://community.esri.com/t5/python-questions/create-db-tables-with-constraints/m-p/694101#M53829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"it does not work" ... error? nothing happened?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 May 2017 00:13:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-db-tables-with-constraints/m-p/694101#M53829</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-05-16T00:13:02Z</dc:date>
    </item>
  </channel>
</rss>

