1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Defining Constraints and Indexes
—
SQLAlchemy 0.9 Documentation
</title>
<!-- begin iterate through SQLA + sphinx environment css_files -->
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/docs.css" type="text/css" />
<link rel="stylesheet" href="../_static/sphinx_paramlinks.css" type="text/css" />
<link rel="stylesheet" href="../_static/changelog.css" type="text/css" />
<!-- end iterate through SQLA + sphinx environment css_files -->
<!-- begin layout.mako headers -->
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.9.8',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<!-- begin iterate through sphinx environment script_files -->
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<!-- end iterate through sphinx environment script_files -->
<script type="text/javascript" src="../_static/detectmobile.js"></script>
<script type="text/javascript" src="../_static/init.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="top" title="SQLAlchemy 0.9 Documentation" href="../index.html" />
<link rel="up" title="Schema Definition Language" href="schema.html" />
<link rel="next" title="Customizing DDL" href="ddl.html" />
<link rel="prev" title="Column Insert/Update Defaults" href="defaults.html" />
<!-- end layout.mako headers -->
</head>
<body>
<div id="docs-container">
<div id="docs-top-navigation-container" class="body-background">
<div id="docs-header">
<div id="docs-version-header">
Release: <span class="version-num">0.9.8</span> | Release Date: October 13, 2014
</div>
<h1>SQLAlchemy 0.9 Documentation</h1>
</div>
</div>
<div id="docs-body-container">
<div id="fixed-sidebar" class="withsidebar">
<div id="docs-sidebar-popout">
<h3><a href="../index.html">SQLAlchemy 0.9 Documentation</a></h3>
<p id="sidebar-paginate">
<a href="schema.html" title="Schema Definition Language">Up</a> |
<a href="defaults.html" title="Column Insert/Update Defaults">Prev</a> |
<a href="ddl.html" title="Customizing DDL">Next</a>
</p>
<p id="sidebar-topnav">
<a href="../index.html">Contents</a> |
<a href="../genindex.html">Index</a>
</p>
<div id="sidebar-search">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="12" /> <input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div id="docs-sidebar">
<h3><a href="#">
Defining Constraints and Indexes
</a></h3>
<ul>
<li><a class="reference internal" href="#">Defining Constraints and Indexes</a><ul>
<li><a class="reference internal" href="#defining-foreign-keys">Defining Foreign Keys</a><ul>
<li><a class="reference internal" href="#creating-dropping-foreign-key-constraints-via-alter">Creating/Dropping Foreign Key Constraints via ALTER</a></li>
<li><a class="reference internal" href="#on-update-and-on-delete">ON UPDATE and ON DELETE</a></li>
</ul>
</li>
<li><a class="reference internal" href="#unique-constraint">UNIQUE Constraint</a></li>
<li><a class="reference internal" href="#check-constraint">CHECK Constraint</a></li>
<li><a class="reference internal" href="#primary-key-constraint">PRIMARY KEY Constraint</a></li>
<li><a class="reference internal" href="#setting-up-constraints-when-using-the-declarative-orm-extension">Setting up Constraints when using the Declarative ORM Extension</a></li>
<li><a class="reference internal" href="#configuring-constraint-naming-conventions">Configuring Constraint Naming Conventions</a></li>
<li><a class="reference internal" href="#constraints-api">Constraints API</a></li>
<li><a class="reference internal" href="#indexes">Indexes</a><ul>
<li><a class="reference internal" href="#functional-indexes">Functional Indexes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#index-api">Index API</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="docs-body" class="withsidebar" >
<span class="target" id="module-sqlalchemy.schema"><span id="metadata-constraints"></span><span id="metadata-constraints-toplevel"></span></span><div class="section" id="defining-constraints-and-indexes">
<h1>Defining Constraints and Indexes<a class="headerlink" href="#defining-constraints-and-indexes" title="Permalink to this headline">¶</a></h1>
<p id="metadata-foreignkeys">This section will discuss SQL <a class="reference internal" href="../glossary.html#term-constraints"><em class="xref std std-term">constraints</em></a> and indexes. In SQLAlchemy
the key classes include <a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a> and <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a>.</p>
<div class="section" id="defining-foreign-keys">
<h2>Defining Foreign Keys<a class="headerlink" href="#defining-foreign-keys" title="Permalink to this headline">¶</a></h2>
<p>A <em>foreign key</em> in SQL is a table-level construct that constrains one or more
columns in that table to only allow values that are present in a different set
of columns, typically but not always located on a different table. We call the
columns which are constrained the <em>foreign key</em> columns and the columns which
they are constrained towards the <em>referenced</em> columns. The referenced columns
almost always define the primary key for their owning table, though there are
exceptions to this. The foreign key is the “joint” that connects together
pairs of rows which have a relationship with each other, and SQLAlchemy
assigns very deep importance to this concept in virtually every area of its
operation.</p>
<p>In SQLAlchemy as well as in DDL, foreign key constraints can be defined as
additional attributes within the table clause, or for single-column foreign
keys they may optionally be specified within the definition of a single
column. The single column foreign key is more common, and at the column level
is specified by constructing a <a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> object
as an argument to a <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">user_preference</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'user_preference'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'pref_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'user_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">"user.user_id"</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'pref_name'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">40</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'pref_value'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">100</span><span class="p">))</span>
<span class="p">)</span></pre></div>
</div>
<p>Above, we define a new table <tt class="docutils literal"><span class="pre">user_preference</span></tt> for which each row must
contain a value in the <tt class="docutils literal"><span class="pre">user_id</span></tt> column that also exists in the <tt class="docutils literal"><span class="pre">user</span></tt>
table’s <tt class="docutils literal"><span class="pre">user_id</span></tt> column.</p>
<p>The argument to <a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> is most commonly a
string of the form <em><tablename>.<columnname></em>, or for a table in a remote
schema or “owner” of the form <em><schemaname>.<tablename>.<columnname></em>. It may
also be an actual <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object, which as we’ll
see later is accessed from an existing <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
object via its <tt class="docutils literal"><span class="pre">c</span></tt> collection:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">ForeignKey</span><span class="p">(</span><span class="n">user</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">user_id</span><span class="p">)</span></pre></div>
</div>
<p>The advantage to using a string is that the in-python linkage between <tt class="docutils literal"><span class="pre">user</span></tt>
and <tt class="docutils literal"><span class="pre">user_preference</span></tt> is resolved only when first needed, so that table
objects can be easily spread across multiple modules and defined in any order.</p>
<p>Foreign keys may also be defined at the table level, using the
<a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a> object. This object can
describe a single- or multi-column foreign key. A multi-column foreign key is
known as a <em>composite</em> foreign key, and almost always references a table that
has a composite primary key. Below we define a table <tt class="docutils literal"><span class="pre">invoice</span></tt> which has a
composite primary key:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">invoice</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'invoice'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'invoice_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'ref_num'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'description'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">60</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<p>And then a table <tt class="docutils literal"><span class="pre">invoice_item</span></tt> with a composite foreign key referencing
<tt class="docutils literal"><span class="pre">invoice</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">invoice_item</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'invoice_item'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'item_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'item_name'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">60</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'invoice_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'ref_num'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
<span class="n">ForeignKeyConstraint</span><span class="p">([</span><span class="s">'invoice_id'</span><span class="p">,</span> <span class="s">'ref_num'</span><span class="p">],</span> <span class="p">[</span><span class="s">'invoice.invoice_id'</span><span class="p">,</span> <span class="s">'invoice.ref_num'</span><span class="p">])</span>
<span class="p">)</span></pre></div>
</div>
<p>It’s important to note that the
<a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a> is the only way to define a
composite foreign key. While we could also have placed individual
<a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> objects on both the
<tt class="docutils literal"><span class="pre">invoice_item.invoice_id</span></tt> and <tt class="docutils literal"><span class="pre">invoice_item.ref_num</span></tt> columns, SQLAlchemy
would not be aware that these two values should be paired together - it would
be two individual foreign key constraints instead of a single composite
foreign key referencing two columns.</p>
<div class="section" id="creating-dropping-foreign-key-constraints-via-alter">
<span id="use-alter"></span><h3>Creating/Dropping Foreign Key Constraints via ALTER<a class="headerlink" href="#creating-dropping-foreign-key-constraints-via-alter" title="Permalink to this headline">¶</a></h3>
<p>In all the above examples, the <a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> object
causes the “REFERENCES” keyword to be added inline to a column definition
within a “CREATE TABLE” statement when
<a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData.create_all" title="sqlalchemy.schema.MetaData.create_all"><tt class="xref py py-func docutils literal"><span class="pre">create_all()</span></tt></a> is issued, and
<a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a> invokes the “CONSTRAINT”
keyword inline with “CREATE TABLE”. There are some cases where this is
undesirable, particularly when two tables reference each other mutually, each
with a foreign key referencing the other. In such a situation at least one of
the foreign key constraints must be generated after both tables have been
built. To support such a scheme, <a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> and
<a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a> offer the flag
<tt class="docutils literal"><span class="pre">use_alter=True</span></tt>. When using this flag, the constraint will be generated
using a definition similar to “ALTER TABLE <tablename> ADD CONSTRAINT <name>
...”. Since a name is required, the <tt class="docutils literal"><span class="pre">name</span></tt> attribute must also be specified.
For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'node'</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'node_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'primary_element'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span>
<span class="n">ForeignKey</span><span class="p">(</span><span class="s">'element.element_id'</span><span class="p">,</span> <span class="n">use_alter</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">'fk_node_element_id'</span><span class="p">)</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="n">element</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'element'</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'element_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'parent_node_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">ForeignKeyConstraint</span><span class="p">(</span>
<span class="p">[</span><span class="s">'parent_node_id'</span><span class="p">],</span>
<span class="p">[</span><span class="s">'node.node_id'</span><span class="p">],</span>
<span class="n">use_alter</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="s">'fk_element_parent_node_id'</span>
<span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
</div>
<div class="section" id="on-update-and-on-delete">
<span id="on-update-on-delete"></span><h3>ON UPDATE and ON DELETE<a class="headerlink" href="#on-update-and-on-delete" title="Permalink to this headline">¶</a></h3>
<p>Most databases support <em>cascading</em> of foreign key values, that is the when a
parent row is updated the new value is placed in child rows, or when the
parent row is deleted all corresponding child rows are set to null or deleted.
In data definition language these are specified using phrases like “ON UPDATE
CASCADE”, “ON DELETE CASCADE”, and “ON DELETE SET NULL”, corresponding to
foreign key constraints. The phrase after “ON UPDATE” or “ON DELETE” may also
other allow other phrases that are specific to the database in use. The
<a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> and
<a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a> objects support the
generation of this clause via the <tt class="docutils literal"><span class="pre">onupdate</span></tt> and <tt class="docutils literal"><span class="pre">ondelete</span></tt> keyword
arguments. The value is any string which will be output after the appropriate
“ON UPDATE” or “ON DELETE” phrase:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">child</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'child'</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span>
<span class="n">ForeignKey</span><span class="p">(</span><span class="s">'parent.id'</span><span class="p">,</span> <span class="n">onupdate</span><span class="o">=</span><span class="s">"CASCADE"</span><span class="p">,</span> <span class="n">ondelete</span><span class="o">=</span><span class="s">"CASCADE"</span><span class="p">),</span>
<span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="n">composite</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'composite'</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'rev_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'note_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">ForeignKeyConstraint</span><span class="p">(</span>
<span class="p">[</span><span class="s">'rev_id'</span><span class="p">,</span> <span class="s">'note_id'</span><span class="p">],</span>
<span class="p">[</span><span class="s">'revisions.id'</span><span class="p">,</span> <span class="s">'revisions.note_id'</span><span class="p">],</span>
<span class="n">onupdate</span><span class="o">=</span><span class="s">"CASCADE"</span><span class="p">,</span> <span class="n">ondelete</span><span class="o">=</span><span class="s">"SET NULL"</span>
<span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<p>Note that these clauses are not supported on SQLite, and require <tt class="docutils literal"><span class="pre">InnoDB</span></tt>
tables when used with MySQL. They may also not be supported on other
databases.</p>
</div>
</div>
<div class="section" id="unique-constraint">
<h2>UNIQUE Constraint<a class="headerlink" href="#unique-constraint" title="Permalink to this headline">¶</a></h2>
<p>Unique constraints can be created anonymously on a single column using the
<tt class="docutils literal"><span class="pre">unique</span></tt> keyword on <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>. Explicitly named
unique constraints and/or those with multiple columns are created via the
<a class="reference internal" href="#sqlalchemy.schema.UniqueConstraint" title="sqlalchemy.schema.UniqueConstraint"><tt class="xref py py-class docutils literal"><span class="pre">UniqueConstraint</span></tt></a> table-level construct.</p>
<div class="highlight-python+sql"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">UniqueConstraint</span>
<span class="n">meta</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
<span class="n">mytable</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'mytable'</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
<span class="c"># per-column anonymous unique constraint</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col1'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">unique</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col2'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col3'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="c"># explicit/composite unique constraint. 'name' is optional.</span>
<span class="n">UniqueConstraint</span><span class="p">(</span><span class="s">'col2'</span><span class="p">,</span> <span class="s">'col3'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">'uix_1'</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
</div>
<div class="section" id="check-constraint">
<h2>CHECK Constraint<a class="headerlink" href="#check-constraint" title="Permalink to this headline">¶</a></h2>
<p>Check constraints can be named or unnamed and can be created at the Column or
Table level, using the <a class="reference internal" href="#sqlalchemy.schema.CheckConstraint" title="sqlalchemy.schema.CheckConstraint"><tt class="xref py py-class docutils literal"><span class="pre">CheckConstraint</span></tt></a> construct.
The text of the check constraint is passed directly through to the database,
so there is limited “database independent” behavior. Column level check
constraints generally should only refer to the column to which they are
placed, while table level constraints can refer to any columns in the table.</p>
<p>Note that some databases do not actively support check constraints such as
MySQL.</p>
<div class="highlight-python+sql"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">CheckConstraint</span>
<span class="n">meta</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
<span class="n">mytable</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'mytable'</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
<span class="c"># per-column CHECK constraint</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col1'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">CheckConstraint</span><span class="p">(</span><span class="s">'col1>5'</span><span class="p">)),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col2'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col3'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="c"># table level CHECK constraint. 'name' is optional.</span>
<span class="n">CheckConstraint</span><span class="p">(</span><span class="s">'col2 > col3 + 5'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">'check1'</span><span class="p">)</span>
<span class="p">)</span>
<a href='#' class='sql_link'>sql</a><span class="n">mytable</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">engine</span><span class="p">)</span>
<div class='popup_sql'>CREATE TABLE mytable (
col1 INTEGER CHECK (col1>5),
col2 INTEGER,
col3 INTEGER,
CONSTRAINT check1 CHECK (col2 > col3 + 5)
)</div></pre></div>
</div>
</div>
<div class="section" id="primary-key-constraint">
<h2>PRIMARY KEY Constraint<a class="headerlink" href="#primary-key-constraint" title="Permalink to this headline">¶</a></h2>
<p>The primary key constraint of any <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object is implicitly
present, based on the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects that are marked with the
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column.params.primary_key" title="sqlalchemy.schema.Column"><tt class="xref py py-paramref docutils literal"><span class="pre">Column.primary_key</span></tt></a> flag. The <a class="reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a>
object provides explicit access to this constraint, which includes the
option of being configured directly:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">PrimaryKeyConstraint</span>
<span class="n">my_table</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'mytable'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'version_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'data'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">)),</span>
<span class="n">PrimaryKeyConstraint</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="s">'version_id'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">'mytable_pk'</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a> - detailed API documentation.</p>
</div>
</div>
<div class="section" id="setting-up-constraints-when-using-the-declarative-orm-extension">
<h2>Setting up Constraints when using the Declarative ORM Extension<a class="headerlink" href="#setting-up-constraints-when-using-the-declarative-orm-extension" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> is the SQLAlchemy Core construct that allows one to define
table metadata, which among other things can be used by the SQLAlchemy ORM
as a target to map a class. The <a class="reference internal" href="../orm/extensions/declarative.html"><em>Declarative</em></a>
extension allows the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object to be created automatically, given
the contents of the table primarily as a mapping of <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects.</p>
<p>To apply table-level constraint objects such as <a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a>
to a table defined using Declarative, use the <tt class="docutils literal"><span class="pre">__table_args__</span></tt> attribute,
described at <a class="reference internal" href="../orm/extensions/declarative.html#declarative-table-args"><em>Table Configuration</em></a>.</p>
</div>
<div class="section" id="configuring-constraint-naming-conventions">
<span id="constraint-naming-conventions"></span><h2>Configuring Constraint Naming Conventions<a class="headerlink" href="#configuring-constraint-naming-conventions" title="Permalink to this headline">¶</a></h2>
<p>Relational databases typically assign explicit names to all constraints and
indexes. In the common case that a table is created using <tt class="docutils literal"><span class="pre">CREATE</span> <span class="pre">TABLE</span></tt>
where constraints such as CHECK, UNIQUE, and PRIMARY KEY constraints are
produced inline with the table definition, the database usually has a system
in place in which names are automatically assigned to these constraints, if
a name is not otherwise specified. When an existing database table is altered
in a database using a command such as <tt class="docutils literal"><span class="pre">ALTER</span> <span class="pre">TABLE</span></tt>, this command typically
needs to specify expicit names for new constraints as well as be able to
specify the name of an existing constraint that is to be dropped or modified.</p>
<p>Constraints can be named explicitly using the <a class="reference internal" href="#sqlalchemy.schema.Constraint.params.name" title="sqlalchemy.schema.Constraint"><tt class="xref py py-paramref docutils literal"><span class="pre">Constraint.name</span></tt></a> parameter,
and for indexes the <a class="reference internal" href="#sqlalchemy.schema.Index.params.name" title="sqlalchemy.schema.Index"><tt class="xref py py-paramref docutils literal"><span class="pre">Index.name</span></tt></a> parameter. However, in the
case of constraints this parameter is optional. There are also the use
cases of using the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column.params.unique" title="sqlalchemy.schema.Column"><tt class="xref py py-paramref docutils literal"><span class="pre">Column.unique</span></tt></a> and <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column.params.index" title="sqlalchemy.schema.Column"><tt class="xref py py-paramref docutils literal"><span class="pre">Column.index</span></tt></a>
parameters which create <a class="reference internal" href="#sqlalchemy.schema.UniqueConstraint" title="sqlalchemy.schema.UniqueConstraint"><tt class="xref py py-class docutils literal"><span class="pre">UniqueConstraint</span></tt></a> and <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> objects
without an explicit name being specified.</p>
<p>The use case of alteration of existing tables and constraints can be handled
by schema migration tools such as <a class="reference external" href="http://http://alembic.readthedocs.org/">Alembic</a>.
However, neither Alembic nor SQLAlchemy currently create names for constraint
objects where the name is otherwise unspecified, leading to the case where
being able to alter existing constraints means that one must reverse-engineer
the naming system used by the relational database to auto-assign names,
or that care must be taken to ensure that all constraints are named.</p>
<p>In contrast to having to assign explicit names to all <a class="reference internal" href="#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">Constraint</span></tt></a>
and <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> objects, automated naming schemes can be constructed
using events. This approach has the advantage that constraints will get
a consistent naming scheme without the need for explicit name parameters
throughout the code, and also that the convention takes place just as well
for those constraints and indexes produced by the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column.params.unique" title="sqlalchemy.schema.Column"><tt class="xref py py-paramref docutils literal"><span class="pre">Column.unique</span></tt></a>
and <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column.params.index" title="sqlalchemy.schema.Column"><tt class="xref py py-paramref docutils literal"><span class="pre">Column.index</span></tt></a> parameters. As of SQLAlchemy 0.9.2 this
event-based approach is included, and can be configured using the argument
<a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData.params.naming_convention" title="sqlalchemy.schema.MetaData"><tt class="xref py py-paramref docutils literal"><span class="pre">MetaData.naming_convention</span></tt></a>.</p>
<p><a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData.params.naming_convention" title="sqlalchemy.schema.MetaData"><tt class="xref py py-paramref docutils literal"><span class="pre">MetaData.naming_convention</span></tt></a> refers to a dictionary which accepts
the <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> class or individual <a class="reference internal" href="#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">Constraint</span></tt></a> classes as keys,
and Python string templates as values. It also accepts a series of
string-codes as alternative keys, <tt class="docutils literal"><span class="pre">"fk"</span></tt>, <tt class="docutils literal"><span class="pre">"pk"</span></tt>,
<tt class="docutils literal"><span class="pre">"ix"</span></tt>, <tt class="docutils literal"><span class="pre">"ck"</span></tt>, <tt class="docutils literal"><span class="pre">"uq"</span></tt> for foreign key, primary key, index,
check, and unique constraint, respectively. The string templates in this
dictionary are used whenever a constraint or index is associated with this
<a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> object that does not have an existing name given (including
one exception case where an existing name can be further embellished).</p>
<p>An example naming convention that suits basic cases is as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">convention</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">"ix"</span><span class="p">:</span> <span class="s">'ix_</span><span class="si">%(column_0_label)s</span><span class="s">'</span><span class="p">,</span>
<span class="s">"uq"</span><span class="p">:</span> <span class="s">"uq_</span><span class="si">%(table_name)s</span><span class="s">_</span><span class="si">%(column_0_name)s</span><span class="s">"</span><span class="p">,</span>
<span class="s">"ck"</span><span class="p">:</span> <span class="s">"ck_</span><span class="si">%(table_name)s</span><span class="s">_</span><span class="si">%(constraint_name)s</span><span class="s">"</span><span class="p">,</span>
<span class="s">"fk"</span><span class="p">:</span> <span class="s">"fk_</span><span class="si">%(table_name)s</span><span class="s">_</span><span class="si">%(column_0_name)s</span><span class="s">_</span><span class="si">%(referred_table_name)s</span><span class="s">"</span><span class="p">,</span>
<span class="s">"pk"</span><span class="p">:</span> <span class="s">"pk_</span><span class="si">%(table_name)s</span><span class="s">"</span>
<span class="p">}</span>
<span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">(</span><span class="n">naming_convention</span><span class="o">=</span><span class="n">convention</span><span class="p">)</span></pre></div>
</div>
<p>The above convention will establish names for all constraints within
the target <a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> collection.
For example, we can observe the name produced when we create an unnamed
<a class="reference internal" href="#sqlalchemy.schema.UniqueConstraint" title="sqlalchemy.schema.UniqueConstraint"><tt class="xref py py-class docutils literal"><span class="pre">UniqueConstraint</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">user_table</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'user'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'name'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">UniqueConstraint</span><span class="p">(</span><span class="s">'name'</span><span class="p">)</span>
<span class="gp">... </span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="n">user_table</span><span class="o">.</span><span class="n">constraints</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">name</span>
<span class="go">'uq_user_name'</span></pre></div>
</div>
<p>This same feature takes effect even if we just use the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column.params.unique" title="sqlalchemy.schema.Column"><tt class="xref py py-paramref docutils literal"><span class="pre">Column.unique</span></tt></a>
flag:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">user_table</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'user'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'name'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">unique</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="gp">... </span> <span class="p">)</span>
<span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="n">user_table</span><span class="o">.</span><span class="n">constraints</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">name</span>
<span class="go">'uq_user_name'</span></pre></div>
</div>
<p>A key advantage to the naming convention approach is that the names are established
at Python construction time, rather than at DDL emit time. The effect this has
when using Alembic’s <tt class="docutils literal"><span class="pre">--autogenerate</span></tt> feature is that the naming convention
will be explicit when a new migration script is generated:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">upgrade</span><span class="p">():</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_unique_constraint</span><span class="p">(</span><span class="s">"uq_user_name"</span><span class="p">,</span> <span class="s">"user"</span><span class="p">,</span> <span class="p">[</span><span class="s">"name"</span><span class="p">])</span></pre></div>
</div>
<p>The above <tt class="docutils literal"><span class="pre">"uq_user_name"</span></tt> string was copied from the <a class="reference internal" href="#sqlalchemy.schema.UniqueConstraint" title="sqlalchemy.schema.UniqueConstraint"><tt class="xref py py-class docutils literal"><span class="pre">UniqueConstraint</span></tt></a>
object that <tt class="docutils literal"><span class="pre">--autogenerate</span></tt> located in our metadata.</p>
<p>The default value for <a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData.params.naming_convention" title="sqlalchemy.schema.MetaData"><tt class="xref py py-paramref docutils literal"><span class="pre">MetaData.naming_convention</span></tt></a> handles
the long-standing SQLAlchemy behavior of assigning a name to a <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a>
object that is created using the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column.params.index" title="sqlalchemy.schema.Column"><tt class="xref py py-paramref docutils literal"><span class="pre">Column.index</span></tt></a> parameter:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">sqlalchemy.sql.schema</span> <span class="kn">import</span> <span class="n">DEFAULT_NAMING_CONVENTION</span>
<span class="gp">>>> </span><span class="n">DEFAULT_NAMING_CONVENTION</span>
<span class="go">immutabledict({'ix': 'ix_%(column_0_label)s'})</span></pre></div>
</div>
<p>The tokens available include <tt class="docutils literal"><span class="pre">%(table_name)s</span></tt>,
<tt class="docutils literal"><span class="pre">%(referred_table_name)s</span></tt>, <tt class="docutils literal"><span class="pre">%(column_0_name)s</span></tt>, <tt class="docutils literal"><span class="pre">%(column_0_label)s</span></tt>,
<tt class="docutils literal"><span class="pre">%(column_0_key)s</span></tt>, <tt class="docutils literal"><span class="pre">%(referred_column_0_name)s</span></tt>, and <tt class="docutils literal"><span class="pre">%(constraint_name)s</span></tt>;
the documentation for <a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData.params.naming_convention" title="sqlalchemy.schema.MetaData"><tt class="xref py py-paramref docutils literal"><span class="pre">MetaData.naming_convention</span></tt></a> describes each
individually. New tokens can also be added, by specifying an additional
token and a callable within the naming_convention dictionary. For example,
if we wanted to name our foreign key constraints using a GUID scheme,
we could do that as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">uuid</span>
<span class="k">def</span> <span class="nf">fk_guid</span><span class="p">(</span><span class="n">constraint</span><span class="p">,</span> <span class="n">table</span><span class="p">):</span>
<span class="n">str_tokens</span> <span class="o">=</span> <span class="p">[</span>
<span class="n">table</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
<span class="n">element</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">element</span> <span class="ow">in</span> <span class="n">constraint</span><span class="o">.</span><span class="n">elements</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
<span class="n">element</span><span class="o">.</span><span class="n">target_fullname</span> <span class="k">for</span> <span class="n">element</span> <span class="ow">in</span> <span class="n">constraint</span><span class="o">.</span><span class="n">elements</span>
<span class="p">]</span>
<span class="n">guid</span> <span class="o">=</span> <span class="n">uuid</span><span class="o">.</span><span class="n">uuid5</span><span class="p">(</span><span class="n">uuid</span><span class="o">.</span><span class="n">NAMESPACE_OID</span><span class="p">,</span> <span class="s">"_"</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">str_tokens</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s">'ascii'</span><span class="p">))</span>
<span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">guid</span><span class="p">)</span>
<span class="n">convention</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">"fk_guid"</span><span class="p">:</span> <span class="n">fk_guid</span><span class="p">,</span>
<span class="s">"ix"</span><span class="p">:</span> <span class="s">'ix_</span><span class="si">%(column_0_label)s</span><span class="s">'</span><span class="p">,</span>
<span class="s">"fk"</span><span class="p">:</span> <span class="s">"fk_</span><span class="si">%(fk_guid)s</span><span class="s">"</span><span class="p">,</span>
<span class="p">}</span></pre></div>
</div>
<p>Above, when we create a new <a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a>, we will get a
name as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">(</span><span class="n">naming_convention</span><span class="o">=</span><span class="n">convention</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">user_table</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'user'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'version'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'data'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>
<span class="gp">... </span> <span class="p">)</span>
<span class="gp">>>> </span><span class="n">address_table</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'address'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'user_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'user_version_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">)</span>
<span class="gp">... </span> <span class="p">)</span>
<span class="gp">>>> </span><span class="n">fk</span> <span class="o">=</span> <span class="n">ForeignKeyConstraint</span><span class="p">([</span><span class="s">'user_id'</span><span class="p">,</span> <span class="s">'user_version_id'</span><span class="p">],</span>
<span class="gp">... </span> <span class="p">[</span><span class="s">'user.id'</span><span class="p">,</span> <span class="s">'user.version'</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">address_table</span><span class="o">.</span><span class="n">append_constraint</span><span class="p">(</span><span class="n">fk</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">fk</span><span class="o">.</span><span class="n">name</span>
<span class="go">fk_0cd51ab5-8d70-56e8-a83c-86661737766d</span></pre></div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData.params.naming_convention" title="sqlalchemy.schema.MetaData"><tt class="xref py py-paramref docutils literal"><span class="pre">MetaData.naming_convention</span></tt></a> - for additional usage details
as well as a listing of all available naming components.</p>
<p class="last"><a class="reference external" href="http://alembic.readthedocs.org/en/latest/tutorial.html#tutorial-constraint-names" title="(in Alembic v0.7.0)"><em>The Importance of Naming Constraints</em></a> - in the Alembic documentation.</p>
</div>
<div class="versionadded">
<p><span>New in version 0.9.2: </span>Added the <a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData.params.naming_convention" title="sqlalchemy.schema.MetaData"><tt class="xref py py-paramref docutils literal"><span class="pre">MetaData.naming_convention</span></tt></a> argument.</p>
</div>
</div>
<div class="section" id="constraints-api">
<h2>Constraints API<a class="headerlink" href="#constraints-api" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="sqlalchemy.schema.Constraint">
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">Constraint</tt><big>(</big><em>name=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>_create_rule=None</em>, <em>**dialect_kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Constraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.base.DialectKWArgs</span></tt></a>, <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.SchemaItem</span></tt></a></p>
<p>A table-level SQL constraint.</p>
<dl class="method">
<dt id="sqlalchemy.schema.Constraint.__init__">
<tt class="descname">__init__</tt><big>(</big><em>name=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>_create_rule=None</em>, <em>**dialect_kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Constraint.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a SQL constraint.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.Constraint.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Constraint.params.name">¶</a> – Optional, the in-database name of this <tt class="docutils literal"><span class="pre">Constraint</span></tt>.</li>
<li><span class="target" id="sqlalchemy.schema.Constraint.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Constraint.params.deferrable">¶</a> – Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when
issuing DDL for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.Constraint.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Constraint.params.initially">¶</a> – Optional string. If set, emit INITIALLY <value> when issuing DDL
for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.Constraint.params._create_rule"></span><strong>_create_rule</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Constraint.params._create_rule">¶</a> – <p>a callable which is passed the DDLCompiler object during
compilation. Returns True or False to signal inline generation of
this Constraint.</p>
<p>The AddConstraint and DropConstraint DDL constructs provide
DDLElement’s more comprehensive “conditional DDL” approach that is
passed a database connection when DDL is being issued. _create_rule
is instead called during any CREATE TABLE compilation, where there
may not be any transaction/connection in progress. However, it
allows conditional compilation of the constraint even for backends
which do not support addition of constraints through ALTER TABLE,
which currently includes SQLite.</p>
<p>_create_rule is used by some types to create constraints.
Currently, its call signature is subject to change at any time.</p>
</li>
<li><span class="target" id="sqlalchemy.schema.Constraint.params.**dialect_kw"></span><strong>**dialect_kw</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Constraint.params.**dialect_kw">¶</a> – Additional keyword arguments are dialect
specific, and passed in the form <tt class="docutils literal"><span class="pre"><dialectname>_<argname></span></tt>. See
the documentation regarding an individual dialect at
<a class="reference internal" href="../dialects/index.html"><em>Dialects</em></a> for detail on documented arguments.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="sqlalchemy.schema.CheckConstraint">
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">CheckConstraint</tt><big>(</big><em>sqltext</em>, <em>name=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>table=None</em>, <em>_create_rule=None</em>, <em>_autoattach=True</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.CheckConstraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.Constraint</span></tt></a></p>
<p>A table- or column-level CHECK constraint.</p>
<p>Can be included in the definition of a Table or Column.</p>
<dl class="method">
<dt id="sqlalchemy.schema.CheckConstraint.__init__">
<tt class="descname">__init__</tt><big>(</big><em>sqltext</em>, <em>name=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>table=None</em>, <em>_create_rule=None</em>, <em>_autoattach=True</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.CheckConstraint.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a CHECK constraint.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.CheckConstraint.params.sqltext"></span><strong>sqltext</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.CheckConstraint.params.sqltext">¶</a> – <p>A string containing the constraint definition, which will be used
verbatim, or a SQL expression construct. If given as a string,
the object is converted to a <a class="reference internal" href="types.html#sqlalchemy.types.Text" title="sqlalchemy.types.Text"><tt class="xref py py-class docutils literal"><span class="pre">Text</span></tt></a> object. If the textual
string includes a colon character, escape this using a backslash:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">CheckConstraint</span><span class="p">(</span><span class="s">r"foo ~ E'a(?\:b|c)d"</span><span class="p">)</span></pre></div>
</div>
</li>
<li><span class="target" id="sqlalchemy.schema.CheckConstraint.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.CheckConstraint.params.name">¶</a> – Optional, the in-database name of the constraint.</li>
<li><span class="target" id="sqlalchemy.schema.CheckConstraint.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.CheckConstraint.params.deferrable">¶</a> – Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when
issuing DDL for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.CheckConstraint.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.CheckConstraint.params.initially">¶</a> – Optional string. If set, emit INITIALLY <value> when issuing DDL
for this constraint.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="sqlalchemy.schema.CheckConstraint.argument_for">
<em class="property">classmethod </em><tt class="descname">argument_for</tt><big>(</big><em>dialect_name</em>, <em>argument_name</em>, <em>default</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.CheckConstraint.argument_for" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">argument_for()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>Add a new kind of dialect-specific keyword argument for this class.</p>
<p>E.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Index</span><span class="o">.</span><span class="n">argument_for</span><span class="p">(</span><span class="s">"mydialect"</span><span class="p">,</span> <span class="s">"length"</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
<span class="n">some_index</span> <span class="o">=</span> <span class="n">Index</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span> <span class="s">'b'</span><span class="p">,</span> <span class="n">mydialect_length</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span></pre></div>
</div>
<p>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">DialectKWArgs.argument_for()</span></tt></a> method is a per-argument
way adding extra arguments to the
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> dictionary. This
dictionary provides a list of argument names accepted by various
schema-level constructs on behalf of a dialect.</p>
<p>New dialects should typically specify this dictionary all at once as a
data member of the dialect class. The use case for ad-hoc addition of
argument names is typically for end-user code that is also using
a custom compilation scheme which consumes the additional arguments.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.CheckConstraint.argument_for.params.dialect_name"></span><strong>dialect_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.CheckConstraint.argument_for.params.dialect_name">¶</a> – name of a dialect. The dialect must be
locatable, else a <tt class="xref py py-class docutils literal"><span class="pre">NoSuchModuleError</span></tt> is raised. The
dialect must also include an existing
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> collection, indicating
that it participates in the keyword-argument validation and default
system, else <tt class="xref py py-class docutils literal"><span class="pre">ArgumentError</span></tt> is raised. If the dialect does
not include this collection, then any keyword argument can be
specified on behalf of this dialect already. All dialects packaged
within SQLAlchemy include this collection, however for third party
dialects, support may vary.</li>
<li><span class="target" id="sqlalchemy.schema.CheckConstraint.argument_for.params.argument_name"></span><strong>argument_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.CheckConstraint.argument_for.params.argument_name">¶</a> – name of the parameter.</li>
<li><span class="target" id="sqlalchemy.schema.CheckConstraint.argument_for.params.default"></span><strong>default</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.CheckConstraint.argument_for.params.default">¶</a> – default value of the parameter.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span>New in version 0.9.4.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.CheckConstraint.dialect_kwargs">
<tt class="descname">dialect_kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.CheckConstraint.dialect_kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>The arguments are present here in their original <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt>
format. Only arguments that were actually passed are included;
unlike the <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> collection, which
contains all options known by this dialect including defaults.</p>
<p>The collection is also writable; keys are accepted of the
form <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt> where the value will be assembled
into the list of options.</p>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="versionchanged">
<p><span>Changed in version 0.9.4: </span>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>
collection is now writable.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> - nested dictionary form</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.CheckConstraint.dialect_options">
<tt class="descname">dialect_options</tt><a class="headerlink" href="#sqlalchemy.schema.CheckConstraint.dialect_options" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_options</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>This is a two-level nested registry, keyed to <tt class="docutils literal"><span class="pre"><dialect_name></span></tt>
and <tt class="docutils literal"><span class="pre"><argument_name></span></tt>. For example, the <tt class="docutils literal"><span class="pre">postgresql_where</span></tt>
argument would be locatable as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">arg</span> <span class="o">=</span> <span class="n">my_object</span><span class="o">.</span><span class="n">dialect_options</span><span class="p">[</span><span class="s">'postgresql'</span><span class="p">][</span><span class="s">'where'</span><span class="p">]</span></pre></div>
</div>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a> - flat dictionary form</p>
</div>
</dd></dl>
<dl class="method">
<dt id="sqlalchemy.schema.CheckConstraint.get_children">
<tt class="descname">get_children</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.CheckConstraint.get_children" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.get_children" title="sqlalchemy.schema.SchemaItem.get_children"><tt class="xref py py-meth docutils literal"><span class="pre">get_children()</span></tt></a> <em>method of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>used to allow SchemaVisitor access</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.CheckConstraint.info">
<tt class="descname">info</tt><a class="headerlink" href="#sqlalchemy.schema.CheckConstraint.info" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.info" title="sqlalchemy.schema.SchemaItem.info"><tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Info dictionary associated with the object, allowing user-defined
data to be associated with this <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a>.</p>
<p>The dictionary is automatically generated when first accessed.
It can also be specified in the constructor of some objects,
such as <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> and <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.CheckConstraint.kwargs">
<tt class="descname">kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.CheckConstraint.kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.kwargs" title="sqlalchemy.sql.base.DialectKWArgs.kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A synonym for <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.CheckConstraint.quote">
<tt class="descname">quote</tt><a class="headerlink" href="#sqlalchemy.schema.CheckConstraint.quote" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.quote" title="sqlalchemy.schema.SchemaItem.quote"><tt class="xref py py-attr docutils literal"><span class="pre">quote</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Return the value of the <tt class="docutils literal"><span class="pre">quote</span></tt> flag passed
to this schema object, for those schema items which
have a <tt class="docutils literal"><span class="pre">name</span></tt> field.</p>
<div class="deprecated">
<p><span>Deprecated since version 0.9: </span>Use <tt class="docutils literal"><span class="pre"><obj>.name.quote</span></tt></p>
</div>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="sqlalchemy.schema.ColumnCollectionConstraint">
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">ColumnCollectionConstraint</tt><big>(</big><em>*columns</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ColumnCollectionConstraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.ColumnCollectionMixin</span></tt>, <a class="reference internal" href="#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.Constraint</span></tt></a></p>
<p>A constraint that proxies a ColumnCollection.</p>
<dl class="method">
<dt id="sqlalchemy.schema.ColumnCollectionConstraint.__init__">
<tt class="descname">__init__</tt><big>(</big><em>*columns</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ColumnCollectionConstraint.__init__" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.ColumnCollectionConstraint.params.*columns"></span><strong>*columns</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ColumnCollectionConstraint.params.*columns">¶</a> – A sequence of column names or Column objects.</li>
<li><span class="target" id="sqlalchemy.schema.ColumnCollectionConstraint.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ColumnCollectionConstraint.params.name">¶</a> – Optional, the in-database name of this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.ColumnCollectionConstraint.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ColumnCollectionConstraint.params.deferrable">¶</a> – Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when
issuing DDL for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.ColumnCollectionConstraint.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ColumnCollectionConstraint.params.initially">¶</a> – Optional string. If set, emit INITIALLY <value> when issuing DDL
for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.ColumnCollectionConstraint.params.**kw"></span><strong>**kw</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ColumnCollectionConstraint.params.**kw">¶</a> – other keyword arguments including dialect-specific
arguments are propagated to the <a class="reference internal" href="#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">Constraint</span></tt></a> superclass.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="sqlalchemy.schema.ForeignKey">
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">ForeignKey</tt><big>(</big><em>column</em>, <em>_constraint=None</em>, <em>use_alter=False</em>, <em>name=None</em>, <em>onupdate=None</em>, <em>ondelete=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>link_to_name=False</em>, <em>match=None</em>, <em>**dialect_kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ForeignKey" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.base.DialectKWArgs</span></tt></a>, <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.SchemaItem</span></tt></a></p>
<p>Defines a dependency between two columns.</p>
<p><tt class="docutils literal"><span class="pre">ForeignKey</span></tt> is specified as an argument to a <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object,
e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">t</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">"remote_table"</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">"remote_id"</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">"main_table.id"</span><span class="p">))</span>
<span class="p">)</span></pre></div>
</div>
<p>Note that <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> is only a marker object that defines
a dependency between two columns. The actual constraint
is in all cases represented by the <a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a>
object. This object will be generated automatically when
a <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> is associated with a <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> which
in turn is associated with a <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>. Conversely,
when <a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a> is applied to a <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>,
<tt class="docutils literal"><span class="pre">ForeignKey</span></tt> markers are automatically generated to be
present on each associated <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>, which are also
associated with the constraint object.</p>
<p>Note that you cannot define a “composite” foreign key constraint,
that is a constraint between a grouping of multiple parent/child
columns, using <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> objects. To define this grouping,
the <a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a> object must be used, and applied
to the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>. The associated <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> objects
are created automatically.</p>
<p>The <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> objects associated with an individual
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object are available in the <cite>foreign_keys</cite> collection
of that column.</p>
<p>Further examples of foreign key configuration are in
<em class="xref std std-ref">metadata_foreignkeys</em>.</p>
<dl class="method">
<dt id="sqlalchemy.schema.ForeignKey.__init__">
<tt class="descname">__init__</tt><big>(</big><em>column</em>, <em>_constraint=None</em>, <em>use_alter=False</em>, <em>name=None</em>, <em>onupdate=None</em>, <em>ondelete=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>link_to_name=False</em>, <em>match=None</em>, <em>**dialect_kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a column-level FOREIGN KEY.</p>
<p>The <a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> object when constructed generates a
<a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a> which is associated with the parent
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object’s collection of constraints.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.ForeignKey.params.column"></span><strong>column</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.params.column">¶</a> – <p>A single target column for the key relationship. A
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object or a column name as a string:
<tt class="docutils literal"><span class="pre">tablename.columnkey</span></tt> or <tt class="docutils literal"><span class="pre">schema.tablename.columnkey</span></tt>.
<tt class="docutils literal"><span class="pre">columnkey</span></tt> is the <tt class="docutils literal"><span class="pre">key</span></tt> which has been assigned to the column
(defaults to the column name itself), unless <tt class="docutils literal"><span class="pre">link_to_name</span></tt> is
<tt class="docutils literal"><span class="pre">True</span></tt> in which case the rendered name of the column is used.</p>
<div class="versionadded">
<p><span>New in version 0.7.4: </span>Note that if the schema name is not included, and the
underlying <a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> has a “schema”, that value will
be used.</p>
</div>
</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKey.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.params.name">¶</a> – Optional string. An in-database name for the key if
<cite>constraint</cite> is not provided.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKey.params.onupdate"></span><strong>onupdate</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.params.onupdate">¶</a> – Optional string. If set, emit ON UPDATE <value> when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKey.params.ondelete"></span><strong>ondelete</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.params.ondelete">¶</a> – Optional string. If set, emit ON DELETE <value> when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKey.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.params.deferrable">¶</a> – Optional bool. If set, emit DEFERRABLE or NOT
DEFERRABLE when issuing DDL for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKey.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.params.initially">¶</a> – Optional string. If set, emit INITIALLY <value> when
issuing DDL for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKey.params.link_to_name"></span><strong>link_to_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.params.link_to_name">¶</a> – if True, the string name given in <tt class="docutils literal"><span class="pre">column</span></tt> is
the rendered name of the referenced column, not its locally
assigned <tt class="docutils literal"><span class="pre">key</span></tt>.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKey.params.use_alter"></span><strong>use_alter</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.params.use_alter">¶</a> – passed to the underlying
<a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a> to indicate the constraint should
be generated/dropped externally from the CREATE TABLE/ DROP TABLE
statement. See that classes’ constructor for details.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKey.params.match"></span><strong>match</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.params.match">¶</a> – Optional string. If set, emit MATCH <value> when issuing
DDL for this constraint. Typical values include SIMPLE, PARTIAL
and FULL.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKey.params.**dialect_kw"></span><strong>**dialect_kw</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.params.**dialect_kw">¶</a> – <p>Additional keyword arguments are dialect
specific, and passed in the form <tt class="docutils literal"><span class="pre"><dialectname>_<argname></span></tt>. The
arguments are ultimately handled by a corresponding
<a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a>. See the documentation regarding
an individual dialect at <a class="reference internal" href="../dialects/index.html"><em>Dialects</em></a> for detail on
documented arguments.</p>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="sqlalchemy.schema.ForeignKey.argument_for">
<em class="property">classmethod </em><tt class="descname">argument_for</tt><big>(</big><em>dialect_name</em>, <em>argument_name</em>, <em>default</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.argument_for" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">argument_for()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>Add a new kind of dialect-specific keyword argument for this class.</p>
<p>E.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Index</span><span class="o">.</span><span class="n">argument_for</span><span class="p">(</span><span class="s">"mydialect"</span><span class="p">,</span> <span class="s">"length"</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
<span class="n">some_index</span> <span class="o">=</span> <span class="n">Index</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span> <span class="s">'b'</span><span class="p">,</span> <span class="n">mydialect_length</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span></pre></div>
</div>
<p>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">DialectKWArgs.argument_for()</span></tt></a> method is a per-argument
way adding extra arguments to the
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> dictionary. This
dictionary provides a list of argument names accepted by various
schema-level constructs on behalf of a dialect.</p>
<p>New dialects should typically specify this dictionary all at once as a
data member of the dialect class. The use case for ad-hoc addition of
argument names is typically for end-user code that is also using
a custom compilation scheme which consumes the additional arguments.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.ForeignKey.argument_for.params.dialect_name"></span><strong>dialect_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.argument_for.params.dialect_name">¶</a> – name of a dialect. The dialect must be
locatable, else a <tt class="xref py py-class docutils literal"><span class="pre">NoSuchModuleError</span></tt> is raised. The
dialect must also include an existing
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> collection, indicating
that it participates in the keyword-argument validation and default
system, else <tt class="xref py py-class docutils literal"><span class="pre">ArgumentError</span></tt> is raised. If the dialect does
not include this collection, then any keyword argument can be
specified on behalf of this dialect already. All dialects packaged
within SQLAlchemy include this collection, however for third party
dialects, support may vary.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKey.argument_for.params.argument_name"></span><strong>argument_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.argument_for.params.argument_name">¶</a> – name of the parameter.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKey.argument_for.params.default"></span><strong>default</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.argument_for.params.default">¶</a> – default value of the parameter.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span>New in version 0.9.4.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKey.column">
<tt class="descname">column</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.column" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the target <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> referenced by this
<a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a>.</p>
<p>If no target column has been established, an exception
is raised.</p>
<div class="versionchanged">
<p><span>Changed in version 0.9.0: </span>Foreign key target column resolution now occurs as soon as both
the ForeignKey object and the remote Column to which it refers
are both associated with the same MetaData object.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="sqlalchemy.schema.ForeignKey.copy">
<tt class="descname">copy</tt><big>(</big><em>schema=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Produce a copy of this <a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> object.</p>
<p>The new <a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> will not be bound
to any <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</p>
<p>This method is usually used by the internal
copy procedures of <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>, <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>,
and <a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="sqlalchemy.schema.ForeignKey.copy.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKey.copy.params.schema">¶</a> – The returned <a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> will
reference the original table and column name, qualified
by the given string schema name.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKey.dialect_kwargs">
<tt class="descname">dialect_kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.dialect_kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>The arguments are present here in their original <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt>
format. Only arguments that were actually passed are included;
unlike the <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> collection, which
contains all options known by this dialect including defaults.</p>
<p>The collection is also writable; keys are accepted of the
form <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt> where the value will be assembled
into the list of options.</p>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="versionchanged">
<p><span>Changed in version 0.9.4: </span>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>
collection is now writable.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> - nested dictionary form</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKey.dialect_options">
<tt class="descname">dialect_options</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.dialect_options" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_options</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>This is a two-level nested registry, keyed to <tt class="docutils literal"><span class="pre"><dialect_name></span></tt>
and <tt class="docutils literal"><span class="pre"><argument_name></span></tt>. For example, the <tt class="docutils literal"><span class="pre">postgresql_where</span></tt>
argument would be locatable as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">arg</span> <span class="o">=</span> <span class="n">my_object</span><span class="o">.</span><span class="n">dialect_options</span><span class="p">[</span><span class="s">'postgresql'</span><span class="p">][</span><span class="s">'where'</span><span class="p">]</span></pre></div>
</div>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a> - flat dictionary form</p>
</div>
</dd></dl>
<dl class="method">
<dt id="sqlalchemy.schema.ForeignKey.get_children">
<tt class="descname">get_children</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.get_children" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.get_children" title="sqlalchemy.schema.SchemaItem.get_children"><tt class="xref py py-meth docutils literal"><span class="pre">get_children()</span></tt></a> <em>method of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>used to allow SchemaVisitor access</p>
</dd></dl>
<dl class="method">
<dt id="sqlalchemy.schema.ForeignKey.get_referent">
<tt class="descname">get_referent</tt><big>(</big><em>table</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.get_referent" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> in the given <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
referenced by this <a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a>.</p>
<p>Returns None if this <a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> does not reference the given
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKey.info">
<tt class="descname">info</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.info" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.info" title="sqlalchemy.schema.SchemaItem.info"><tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Info dictionary associated with the object, allowing user-defined
data to be associated with this <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a>.</p>
<p>The dictionary is automatically generated when first accessed.
It can also be specified in the constructor of some objects,
such as <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> and <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKey.kwargs">
<tt class="descname">kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.kwargs" title="sqlalchemy.sql.base.DialectKWArgs.kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A synonym for <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKey.quote">
<tt class="descname">quote</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.quote" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.quote" title="sqlalchemy.schema.SchemaItem.quote"><tt class="xref py py-attr docutils literal"><span class="pre">quote</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Return the value of the <tt class="docutils literal"><span class="pre">quote</span></tt> flag passed
to this schema object, for those schema items which
have a <tt class="docutils literal"><span class="pre">name</span></tt> field.</p>
<div class="deprecated">
<p><span>Deprecated since version 0.9: </span>Use <tt class="docutils literal"><span class="pre"><obj>.name.quote</span></tt></p>
</div>
</dd></dl>
<dl class="method">
<dt id="sqlalchemy.schema.ForeignKey.references">
<tt class="descname">references</tt><big>(</big><em>table</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.references" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the given <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> is referenced by this
<a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKey.target_fullname">
<tt class="descname">target_fullname</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKey.target_fullname" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string based ‘column specification’ for this
<a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a>.</p>
<p>This is usually the equivalent of the string-based “tablename.colname”
argument first passed to the object’s constructor.</p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="sqlalchemy.schema.ForeignKeyConstraint">
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">ForeignKeyConstraint</tt><big>(</big><em>columns</em>, <em>refcolumns</em>, <em>name=None</em>, <em>onupdate=None</em>, <em>ondelete=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>use_alter=False</em>, <em>link_to_name=False</em>, <em>match=None</em>, <em>table=None</em>, <em>**dialect_kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ForeignKeyConstraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.Constraint</span></tt></a></p>
<p>A table-level FOREIGN KEY constraint.</p>
<p>Defines a single column or composite FOREIGN KEY ... REFERENCES
constraint. For a no-frills, single column foreign key, adding a
<a class="reference internal" href="#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> to the definition of a <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> is a
shorthand equivalent for an unnamed, single column
<a class="reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a>.</p>
<p>Examples of foreign key configuration are in <em class="xref std std-ref">metadata_foreignkeys</em>.</p>
<dl class="method">
<dt id="sqlalchemy.schema.ForeignKeyConstraint.__init__">
<tt class="descname">__init__</tt><big>(</big><em>columns</em>, <em>refcolumns</em>, <em>name=None</em>, <em>onupdate=None</em>, <em>ondelete=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>use_alter=False</em>, <em>link_to_name=False</em>, <em>match=None</em>, <em>table=None</em>, <em>**dialect_kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ForeignKeyConstraint.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a composite-capable FOREIGN KEY.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.params.columns"></span><strong>columns</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.params.columns">¶</a> – A sequence of local column names. The named columns
must be defined and present in the parent Table. The names should
match the <tt class="docutils literal"><span class="pre">key</span></tt> given to each column (defaults to the name) unless
<tt class="docutils literal"><span class="pre">link_to_name</span></tt> is True.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.params.refcolumns"></span><strong>refcolumns</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.params.refcolumns">¶</a> – A sequence of foreign column names or Column
objects. The columns must all be located within the same Table.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.params.name">¶</a> – Optional, the in-database name of the key.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.params.onupdate"></span><strong>onupdate</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.params.onupdate">¶</a> – Optional string. If set, emit ON UPDATE <value> when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.params.ondelete"></span><strong>ondelete</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.params.ondelete">¶</a> – Optional string. If set, emit ON DELETE <value> when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.params.deferrable">¶</a> – Optional bool. If set, emit DEFERRABLE or NOT
DEFERRABLE when issuing DDL for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.params.initially">¶</a> – Optional string. If set, emit INITIALLY <value> when
issuing DDL for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.params.link_to_name"></span><strong>link_to_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.params.link_to_name">¶</a> – if True, the string name given in <tt class="docutils literal"><span class="pre">column</span></tt> is
the rendered name of the referenced column, not its locally assigned
<tt class="docutils literal"><span class="pre">key</span></tt>.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.params.use_alter"></span><strong>use_alter</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.params.use_alter">¶</a> – If True, do not emit the DDL for this constraint as
part of the CREATE TABLE definition. Instead, generate it via an
ALTER TABLE statement issued after the full collection of tables
have been created, and drop it via an ALTER TABLE statement before
the full collection of tables are dropped. This is shorthand for the
usage of <a class="reference internal" href="ddl.html#sqlalchemy.schema.AddConstraint" title="sqlalchemy.schema.AddConstraint"><tt class="xref py py-class docutils literal"><span class="pre">AddConstraint</span></tt></a> and <a class="reference internal" href="ddl.html#sqlalchemy.schema.DropConstraint" title="sqlalchemy.schema.DropConstraint"><tt class="xref py py-class docutils literal"><span class="pre">DropConstraint</span></tt></a>
applied as “after-create” and “before-drop” events on the MetaData
object. This is normally used to generate/drop constraints on
objects that are mutually dependent on each other.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.params.match"></span><strong>match</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.params.match">¶</a> – Optional string. If set, emit MATCH <value> when issuing
DDL for this constraint. Typical values include SIMPLE, PARTIAL
and FULL.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.params.**dialect_kw"></span><strong>**dialect_kw</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.params.**dialect_kw">¶</a> – <p>Additional keyword arguments are dialect
specific, and passed in the form <tt class="docutils literal"><span class="pre"><dialectname>_<argname></span></tt>. See
the documentation regarding an individual dialect at
<a class="reference internal" href="../dialects/index.html"><em>Dialects</em></a> for detail on documented arguments.</p>
<blockquote>
<div><div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
</div></blockquote>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="sqlalchemy.schema.ForeignKeyConstraint.argument_for">
<em class="property">classmethod </em><tt class="descname">argument_for</tt><big>(</big><em>dialect_name</em>, <em>argument_name</em>, <em>default</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ForeignKeyConstraint.argument_for" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">argument_for()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>Add a new kind of dialect-specific keyword argument for this class.</p>
<p>E.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Index</span><span class="o">.</span><span class="n">argument_for</span><span class="p">(</span><span class="s">"mydialect"</span><span class="p">,</span> <span class="s">"length"</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
<span class="n">some_index</span> <span class="o">=</span> <span class="n">Index</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span> <span class="s">'b'</span><span class="p">,</span> <span class="n">mydialect_length</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span></pre></div>
</div>
<p>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">DialectKWArgs.argument_for()</span></tt></a> method is a per-argument
way adding extra arguments to the
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> dictionary. This
dictionary provides a list of argument names accepted by various
schema-level constructs on behalf of a dialect.</p>
<p>New dialects should typically specify this dictionary all at once as a
data member of the dialect class. The use case for ad-hoc addition of
argument names is typically for end-user code that is also using
a custom compilation scheme which consumes the additional arguments.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.argument_for.params.dialect_name"></span><strong>dialect_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.argument_for.params.dialect_name">¶</a> – name of a dialect. The dialect must be
locatable, else a <tt class="xref py py-class docutils literal"><span class="pre">NoSuchModuleError</span></tt> is raised. The
dialect must also include an existing
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> collection, indicating
that it participates in the keyword-argument validation and default
system, else <tt class="xref py py-class docutils literal"><span class="pre">ArgumentError</span></tt> is raised. If the dialect does
not include this collection, then any keyword argument can be
specified on behalf of this dialect already. All dialects packaged
within SQLAlchemy include this collection, however for third party
dialects, support may vary.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.argument_for.params.argument_name"></span><strong>argument_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.argument_for.params.argument_name">¶</a> – name of the parameter.</li>
<li><span class="target" id="sqlalchemy.schema.ForeignKeyConstraint.argument_for.params.default"></span><strong>default</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.ForeignKeyConstraint.argument_for.params.default">¶</a> – default value of the parameter.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span>New in version 0.9.4.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKeyConstraint.dialect_kwargs">
<tt class="descname">dialect_kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKeyConstraint.dialect_kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>The arguments are present here in their original <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt>
format. Only arguments that were actually passed are included;
unlike the <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> collection, which
contains all options known by this dialect including defaults.</p>
<p>The collection is also writable; keys are accepted of the
form <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt> where the value will be assembled
into the list of options.</p>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="versionchanged">
<p><span>Changed in version 0.9.4: </span>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>
collection is now writable.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> - nested dictionary form</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKeyConstraint.dialect_options">
<tt class="descname">dialect_options</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKeyConstraint.dialect_options" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_options</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>This is a two-level nested registry, keyed to <tt class="docutils literal"><span class="pre"><dialect_name></span></tt>
and <tt class="docutils literal"><span class="pre"><argument_name></span></tt>. For example, the <tt class="docutils literal"><span class="pre">postgresql_where</span></tt>
argument would be locatable as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">arg</span> <span class="o">=</span> <span class="n">my_object</span><span class="o">.</span><span class="n">dialect_options</span><span class="p">[</span><span class="s">'postgresql'</span><span class="p">][</span><span class="s">'where'</span><span class="p">]</span></pre></div>
</div>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a> - flat dictionary form</p>
</div>
</dd></dl>
<dl class="method">
<dt id="sqlalchemy.schema.ForeignKeyConstraint.get_children">
<tt class="descname">get_children</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ForeignKeyConstraint.get_children" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.get_children" title="sqlalchemy.schema.SchemaItem.get_children"><tt class="xref py py-meth docutils literal"><span class="pre">get_children()</span></tt></a> <em>method of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>used to allow SchemaVisitor access</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKeyConstraint.info">
<tt class="descname">info</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKeyConstraint.info" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.info" title="sqlalchemy.schema.SchemaItem.info"><tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Info dictionary associated with the object, allowing user-defined
data to be associated with this <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a>.</p>
<p>The dictionary is automatically generated when first accessed.
It can also be specified in the constructor of some objects,
such as <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> and <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKeyConstraint.kwargs">
<tt class="descname">kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKeyConstraint.kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.kwargs" title="sqlalchemy.sql.base.DialectKWArgs.kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A synonym for <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.ForeignKeyConstraint.quote">
<tt class="descname">quote</tt><a class="headerlink" href="#sqlalchemy.schema.ForeignKeyConstraint.quote" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.quote" title="sqlalchemy.schema.SchemaItem.quote"><tt class="xref py py-attr docutils literal"><span class="pre">quote</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Return the value of the <tt class="docutils literal"><span class="pre">quote</span></tt> flag passed
to this schema object, for those schema items which
have a <tt class="docutils literal"><span class="pre">name</span></tt> field.</p>
<div class="deprecated">
<p><span>Deprecated since version 0.9: </span>Use <tt class="docutils literal"><span class="pre"><obj>.name.quote</span></tt></p>
</div>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="sqlalchemy.schema.PrimaryKeyConstraint">
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">PrimaryKeyConstraint</tt><big>(</big><em>*columns</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.PrimaryKeyConstraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.schema.ColumnCollectionConstraint" title="sqlalchemy.schema.ColumnCollectionConstraint"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.ColumnCollectionConstraint</span></tt></a></p>
<p>A table-level PRIMARY KEY constraint.</p>
<p>The <a class="reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a> object is present automatically
on any <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object; it is assigned a set of
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects corresponding to those marked with
the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column.params.primary_key" title="sqlalchemy.schema.Column"><tt class="xref py py-paramref docutils literal"><span class="pre">Column.primary_key</span></tt></a> flag:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">my_table</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'mytable'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'version_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">Column</span><span class="p">(</span><span class="s">'data'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">))</span>
<span class="gp">... </span> <span class="p">)</span>
<span class="gp">>>> </span><span class="n">my_table</span><span class="o">.</span><span class="n">primary_key</span>
<span class="go">PrimaryKeyConstraint(</span>
<span class="go"> Column('id', Integer(), table=<mytable>,</span>
<span class="go"> primary_key=True, nullable=False),</span>
<span class="go"> Column('version_id', Integer(), table=<mytable>,</span>
<span class="go"> primary_key=True, nullable=False)</span>
<span class="go">)</span></pre></div>
</div>
<p>The primary key of a <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> can also be specified by using
a <a class="reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a> object explicitly; in this mode of usage,
the “name” of the constraint can also be specified, as well as other
options which may be recognized by dialects:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">my_table</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'mytable'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'version_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'data'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">)),</span>
<span class="n">PrimaryKeyConstraint</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="s">'version_id'</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="s">'mytable_pk'</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<p>The two styles of column-specification should generally not be mixed.
An warning is emitted if the columns present in the
<a class="reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a>
don’t match the columns that were marked as <tt class="docutils literal"><span class="pre">primary_key=True</span></tt>, if both
are present; in this case, the columns are taken strictly from the
<a class="reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a> declaration, and those columns otherwise
marked as <tt class="docutils literal"><span class="pre">primary_key=True</span></tt> are ignored. This behavior is intended to
be backwards compatible with previous behavior.</p>
<div class="versionchanged">
<p><span>Changed in version 0.9.2: </span>Using a mixture of columns within a
<a class="reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a> in addition to columns marked as
<tt class="docutils literal"><span class="pre">primary_key=True</span></tt> now emits a warning if the lists don’t match.
The ultimate behavior of ignoring those columns marked with the flag
only is currently maintained for backwards compatibility; this warning
may raise an exception in a future release.</p>
</div>
<p>For the use case where specific options are to be specified on the
<a class="reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a>, but the usual style of using
<tt class="docutils literal"><span class="pre">primary_key=True</span></tt> flags is still desirable, an empty
<a class="reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a> may be specified, which will take on the
primary key column collection from the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> based on the
flags:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">my_table</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'mytable'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'version_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'data'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">)),</span>
<span class="n">PrimaryKeyConstraint</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'mytable_pk'</span><span class="p">,</span>
<span class="n">mssql_clustered</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<div class="versionadded">
<p><span>New in version 0.9.2: </span>an empty <a class="reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a> may now
be specified for the purposes of establishing keyword arguments with
the constraint, independently of the specification of “primary key”
columns within the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> itself; columns marked as
<tt class="docutils literal"><span class="pre">primary_key=True</span></tt> will be gathered into the empty constraint’s
column collection.</p>
</div>
<dl class="method">
<dt id="sqlalchemy.schema.PrimaryKeyConstraint.__init__">
<tt class="descname">__init__</tt><big>(</big><em>*columns</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.PrimaryKeyConstraint.__init__" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.schema.ColumnCollectionConstraint.__init__" title="sqlalchemy.schema.ColumnCollectionConstraint.__init__"><tt class="xref py py-meth docutils literal"><span class="pre">__init__()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.schema.ColumnCollectionConstraint" title="sqlalchemy.schema.ColumnCollectionConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ColumnCollectionConstraint</span></tt></a></div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.PrimaryKeyConstraint.params.*columns"></span><strong>*columns</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint.params.*columns">¶</a> – A sequence of column names or Column objects.</li>
<li><span class="target" id="sqlalchemy.schema.PrimaryKeyConstraint.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint.params.name">¶</a> – Optional, the in-database name of this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.PrimaryKeyConstraint.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint.params.deferrable">¶</a> – Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when
issuing DDL for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.PrimaryKeyConstraint.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint.params.initially">¶</a> – Optional string. If set, emit INITIALLY <value> when issuing DDL
for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.PrimaryKeyConstraint.params.**kw"></span><strong>**kw</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint.params.**kw">¶</a> – other keyword arguments including dialect-specific
arguments are propagated to the <a class="reference internal" href="#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">Constraint</span></tt></a> superclass.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="sqlalchemy.schema.PrimaryKeyConstraint.argument_for">
<em class="property">classmethod </em><tt class="descname">argument_for</tt><big>(</big><em>dialect_name</em>, <em>argument_name</em>, <em>default</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.PrimaryKeyConstraint.argument_for" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">argument_for()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>Add a new kind of dialect-specific keyword argument for this class.</p>
<p>E.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Index</span><span class="o">.</span><span class="n">argument_for</span><span class="p">(</span><span class="s">"mydialect"</span><span class="p">,</span> <span class="s">"length"</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
<span class="n">some_index</span> <span class="o">=</span> <span class="n">Index</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span> <span class="s">'b'</span><span class="p">,</span> <span class="n">mydialect_length</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span></pre></div>
</div>
<p>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">DialectKWArgs.argument_for()</span></tt></a> method is a per-argument
way adding extra arguments to the
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> dictionary. This
dictionary provides a list of argument names accepted by various
schema-level constructs on behalf of a dialect.</p>
<p>New dialects should typically specify this dictionary all at once as a
data member of the dialect class. The use case for ad-hoc addition of
argument names is typically for end-user code that is also using
a custom compilation scheme which consumes the additional arguments.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.PrimaryKeyConstraint.argument_for.params.dialect_name"></span><strong>dialect_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint.argument_for.params.dialect_name">¶</a> – name of a dialect. The dialect must be
locatable, else a <tt class="xref py py-class docutils literal"><span class="pre">NoSuchModuleError</span></tt> is raised. The
dialect must also include an existing
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> collection, indicating
that it participates in the keyword-argument validation and default
system, else <tt class="xref py py-class docutils literal"><span class="pre">ArgumentError</span></tt> is raised. If the dialect does
not include this collection, then any keyword argument can be
specified on behalf of this dialect already. All dialects packaged
within SQLAlchemy include this collection, however for third party
dialects, support may vary.</li>
<li><span class="target" id="sqlalchemy.schema.PrimaryKeyConstraint.argument_for.params.argument_name"></span><strong>argument_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint.argument_for.params.argument_name">¶</a> – name of the parameter.</li>
<li><span class="target" id="sqlalchemy.schema.PrimaryKeyConstraint.argument_for.params.default"></span><strong>default</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.PrimaryKeyConstraint.argument_for.params.default">¶</a> – default value of the parameter.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span>New in version 0.9.4.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.PrimaryKeyConstraint.dialect_kwargs">
<tt class="descname">dialect_kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.PrimaryKeyConstraint.dialect_kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>The arguments are present here in their original <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt>
format. Only arguments that were actually passed are included;
unlike the <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> collection, which
contains all options known by this dialect including defaults.</p>
<p>The collection is also writable; keys are accepted of the
form <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt> where the value will be assembled
into the list of options.</p>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="versionchanged">
<p><span>Changed in version 0.9.4: </span>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>
collection is now writable.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> - nested dictionary form</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.PrimaryKeyConstraint.dialect_options">
<tt class="descname">dialect_options</tt><a class="headerlink" href="#sqlalchemy.schema.PrimaryKeyConstraint.dialect_options" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_options</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>This is a two-level nested registry, keyed to <tt class="docutils literal"><span class="pre"><dialect_name></span></tt>
and <tt class="docutils literal"><span class="pre"><argument_name></span></tt>. For example, the <tt class="docutils literal"><span class="pre">postgresql_where</span></tt>
argument would be locatable as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">arg</span> <span class="o">=</span> <span class="n">my_object</span><span class="o">.</span><span class="n">dialect_options</span><span class="p">[</span><span class="s">'postgresql'</span><span class="p">][</span><span class="s">'where'</span><span class="p">]</span></pre></div>
</div>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a> - flat dictionary form</p>
</div>
</dd></dl>
<dl class="method">
<dt id="sqlalchemy.schema.PrimaryKeyConstraint.get_children">
<tt class="descname">get_children</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.PrimaryKeyConstraint.get_children" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.get_children" title="sqlalchemy.schema.SchemaItem.get_children"><tt class="xref py py-meth docutils literal"><span class="pre">get_children()</span></tt></a> <em>method of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>used to allow SchemaVisitor access</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.PrimaryKeyConstraint.info">
<tt class="descname">info</tt><a class="headerlink" href="#sqlalchemy.schema.PrimaryKeyConstraint.info" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.info" title="sqlalchemy.schema.SchemaItem.info"><tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Info dictionary associated with the object, allowing user-defined
data to be associated with this <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a>.</p>
<p>The dictionary is automatically generated when first accessed.
It can also be specified in the constructor of some objects,
such as <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> and <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.PrimaryKeyConstraint.kwargs">
<tt class="descname">kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.PrimaryKeyConstraint.kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.kwargs" title="sqlalchemy.sql.base.DialectKWArgs.kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A synonym for <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.PrimaryKeyConstraint.quote">
<tt class="descname">quote</tt><a class="headerlink" href="#sqlalchemy.schema.PrimaryKeyConstraint.quote" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.quote" title="sqlalchemy.schema.SchemaItem.quote"><tt class="xref py py-attr docutils literal"><span class="pre">quote</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Return the value of the <tt class="docutils literal"><span class="pre">quote</span></tt> flag passed
to this schema object, for those schema items which
have a <tt class="docutils literal"><span class="pre">name</span></tt> field.</p>
<div class="deprecated">
<p><span>Deprecated since version 0.9: </span>Use <tt class="docutils literal"><span class="pre"><obj>.name.quote</span></tt></p>
</div>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="sqlalchemy.schema.UniqueConstraint">
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">UniqueConstraint</tt><big>(</big><em>*columns</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.UniqueConstraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.schema.ColumnCollectionConstraint" title="sqlalchemy.schema.ColumnCollectionConstraint"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.ColumnCollectionConstraint</span></tt></a></p>
<p>A table-level UNIQUE constraint.</p>
<p>Defines a single column or composite UNIQUE constraint. For a no-frills,
single column constraint, adding <tt class="docutils literal"><span class="pre">unique=True</span></tt> to the <tt class="docutils literal"><span class="pre">Column</span></tt>
definition is a shorthand equivalent for an unnamed, single column
UniqueConstraint.</p>
<dl class="method">
<dt id="sqlalchemy.schema.UniqueConstraint.__init__">
<tt class="descname">__init__</tt><big>(</big><em>*columns</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.UniqueConstraint.__init__" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.schema.ColumnCollectionConstraint.__init__" title="sqlalchemy.schema.ColumnCollectionConstraint.__init__"><tt class="xref py py-meth docutils literal"><span class="pre">__init__()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.schema.ColumnCollectionConstraint" title="sqlalchemy.schema.ColumnCollectionConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ColumnCollectionConstraint</span></tt></a></div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.UniqueConstraint.params.*columns"></span><strong>*columns</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.UniqueConstraint.params.*columns">¶</a> – A sequence of column names or Column objects.</li>
<li><span class="target" id="sqlalchemy.schema.UniqueConstraint.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.UniqueConstraint.params.name">¶</a> – Optional, the in-database name of this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.UniqueConstraint.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.UniqueConstraint.params.deferrable">¶</a> – Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when
issuing DDL for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.UniqueConstraint.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.UniqueConstraint.params.initially">¶</a> – Optional string. If set, emit INITIALLY <value> when issuing DDL
for this constraint.</li>
<li><span class="target" id="sqlalchemy.schema.UniqueConstraint.params.**kw"></span><strong>**kw</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.UniqueConstraint.params.**kw">¶</a> – other keyword arguments including dialect-specific
arguments are propagated to the <a class="reference internal" href="#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">Constraint</span></tt></a> superclass.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="sqlalchemy.schema.UniqueConstraint.argument_for">
<em class="property">classmethod </em><tt class="descname">argument_for</tt><big>(</big><em>dialect_name</em>, <em>argument_name</em>, <em>default</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.UniqueConstraint.argument_for" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">argument_for()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>Add a new kind of dialect-specific keyword argument for this class.</p>
<p>E.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Index</span><span class="o">.</span><span class="n">argument_for</span><span class="p">(</span><span class="s">"mydialect"</span><span class="p">,</span> <span class="s">"length"</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
<span class="n">some_index</span> <span class="o">=</span> <span class="n">Index</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span> <span class="s">'b'</span><span class="p">,</span> <span class="n">mydialect_length</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span></pre></div>
</div>
<p>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">DialectKWArgs.argument_for()</span></tt></a> method is a per-argument
way adding extra arguments to the
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> dictionary. This
dictionary provides a list of argument names accepted by various
schema-level constructs on behalf of a dialect.</p>
<p>New dialects should typically specify this dictionary all at once as a
data member of the dialect class. The use case for ad-hoc addition of
argument names is typically for end-user code that is also using
a custom compilation scheme which consumes the additional arguments.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.UniqueConstraint.argument_for.params.dialect_name"></span><strong>dialect_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.UniqueConstraint.argument_for.params.dialect_name">¶</a> – name of a dialect. The dialect must be
locatable, else a <tt class="xref py py-class docutils literal"><span class="pre">NoSuchModuleError</span></tt> is raised. The
dialect must also include an existing
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> collection, indicating
that it participates in the keyword-argument validation and default
system, else <tt class="xref py py-class docutils literal"><span class="pre">ArgumentError</span></tt> is raised. If the dialect does
not include this collection, then any keyword argument can be
specified on behalf of this dialect already. All dialects packaged
within SQLAlchemy include this collection, however for third party
dialects, support may vary.</li>
<li><span class="target" id="sqlalchemy.schema.UniqueConstraint.argument_for.params.argument_name"></span><strong>argument_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.UniqueConstraint.argument_for.params.argument_name">¶</a> – name of the parameter.</li>
<li><span class="target" id="sqlalchemy.schema.UniqueConstraint.argument_for.params.default"></span><strong>default</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.UniqueConstraint.argument_for.params.default">¶</a> – default value of the parameter.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span>New in version 0.9.4.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.UniqueConstraint.dialect_kwargs">
<tt class="descname">dialect_kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.UniqueConstraint.dialect_kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>The arguments are present here in their original <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt>
format. Only arguments that were actually passed are included;
unlike the <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> collection, which
contains all options known by this dialect including defaults.</p>
<p>The collection is also writable; keys are accepted of the
form <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt> where the value will be assembled
into the list of options.</p>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="versionchanged">
<p><span>Changed in version 0.9.4: </span>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>
collection is now writable.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> - nested dictionary form</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.UniqueConstraint.dialect_options">
<tt class="descname">dialect_options</tt><a class="headerlink" href="#sqlalchemy.schema.UniqueConstraint.dialect_options" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_options</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>This is a two-level nested registry, keyed to <tt class="docutils literal"><span class="pre"><dialect_name></span></tt>
and <tt class="docutils literal"><span class="pre"><argument_name></span></tt>. For example, the <tt class="docutils literal"><span class="pre">postgresql_where</span></tt>
argument would be locatable as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">arg</span> <span class="o">=</span> <span class="n">my_object</span><span class="o">.</span><span class="n">dialect_options</span><span class="p">[</span><span class="s">'postgresql'</span><span class="p">][</span><span class="s">'where'</span><span class="p">]</span></pre></div>
</div>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a> - flat dictionary form</p>
</div>
</dd></dl>
<dl class="method">
<dt id="sqlalchemy.schema.UniqueConstraint.get_children">
<tt class="descname">get_children</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.UniqueConstraint.get_children" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.get_children" title="sqlalchemy.schema.SchemaItem.get_children"><tt class="xref py py-meth docutils literal"><span class="pre">get_children()</span></tt></a> <em>method of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>used to allow SchemaVisitor access</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.UniqueConstraint.info">
<tt class="descname">info</tt><a class="headerlink" href="#sqlalchemy.schema.UniqueConstraint.info" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.info" title="sqlalchemy.schema.SchemaItem.info"><tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Info dictionary associated with the object, allowing user-defined
data to be associated with this <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a>.</p>
<p>The dictionary is automatically generated when first accessed.
It can also be specified in the constructor of some objects,
such as <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> and <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.UniqueConstraint.kwargs">
<tt class="descname">kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.UniqueConstraint.kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.kwargs" title="sqlalchemy.sql.base.DialectKWArgs.kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A synonym for <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.UniqueConstraint.quote">
<tt class="descname">quote</tt><a class="headerlink" href="#sqlalchemy.schema.UniqueConstraint.quote" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.quote" title="sqlalchemy.schema.SchemaItem.quote"><tt class="xref py py-attr docutils literal"><span class="pre">quote</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Return the value of the <tt class="docutils literal"><span class="pre">quote</span></tt> flag passed
to this schema object, for those schema items which
have a <tt class="docutils literal"><span class="pre">name</span></tt> field.</p>
<div class="deprecated">
<p><span>Deprecated since version 0.9: </span>Use <tt class="docutils literal"><span class="pre"><obj>.name.quote</span></tt></p>
</div>
</dd></dl>
</dd></dl>
<dl class="function">
<dt id="sqlalchemy.schema.conv">
<tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">conv</tt><big>(</big><em>cls</em>, <em>value</em>, <em>quote=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.conv" title="Permalink to this definition">¶</a></dt>
<dd><p>Mark a string indicating that a name has already been converted
by a naming convention.</p>
<p>This is a string subclass that indicates a name that should not be
subject to any further naming conventions.</p>
<p>E.g. when we create a <a class="reference internal" href="#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">Constraint</span></tt></a> using a naming convention
as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">m</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">(</span><span class="n">naming_convention</span><span class="o">=</span><span class="p">{</span>
<span class="s">"ck"</span><span class="p">:</span> <span class="s">"ck_</span><span class="si">%(table_name)s</span><span class="s">_</span><span class="si">%(constraint_name)s</span><span class="s">"</span>
<span class="p">})</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'t'</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">Column</span><span class="p">(</span><span class="s">'x'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">CheckConstraint</span><span class="p">(</span><span class="s">'x > 5'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">'x5'</span><span class="p">))</span></pre></div>
</div>
<p>The name of the above constraint will be rendered as <tt class="docutils literal"><span class="pre">"ck_t_x5"</span></tt>.
That is, the existing name <tt class="docutils literal"><span class="pre">x5</span></tt> is used in the naming convention as the
<tt class="docutils literal"><span class="pre">constraint_name</span></tt> token.</p>
<p>In some situations, such as in migration scripts, we may be rendering
the above <a class="reference internal" href="#sqlalchemy.schema.CheckConstraint" title="sqlalchemy.schema.CheckConstraint"><tt class="xref py py-class docutils literal"><span class="pre">CheckConstraint</span></tt></a> with a name that’s already been
converted. In order to make sure the name isn’t double-modified, the
new name is applied using the <a class="reference internal" href="#sqlalchemy.schema.conv" title="sqlalchemy.schema.conv"><tt class="xref py py-func docutils literal"><span class="pre">schema.conv()</span></tt></a> marker. We can
use this explicitly as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">m</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">(</span><span class="n">naming_convention</span><span class="o">=</span><span class="p">{</span>
<span class="s">"ck"</span><span class="p">:</span> <span class="s">"ck_</span><span class="si">%(table_name)s</span><span class="s">_</span><span class="si">%(constraint_name)s</span><span class="s">"</span>
<span class="p">})</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'t'</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">Column</span><span class="p">(</span><span class="s">'x'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">CheckConstraint</span><span class="p">(</span><span class="s">'x > 5'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">conv</span><span class="p">(</span><span class="s">'ck_t_x5'</span><span class="p">)))</span></pre></div>
</div>
<p>Where above, the <a class="reference internal" href="#sqlalchemy.schema.conv" title="sqlalchemy.schema.conv"><tt class="xref py py-func docutils literal"><span class="pre">schema.conv()</span></tt></a> marker indicates that the constraint
name here is final, and the name will render as <tt class="docutils literal"><span class="pre">"ck_t_x5"</span></tt> and not
<tt class="docutils literal"><span class="pre">"ck_t_ck_t_x5"</span></tt></p>
<div class="versionadded">
<p><span>New in version 0.9.4.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#constraint-naming-conventions"><em>Configuring Constraint Naming Conventions</em></a></p>
</div>
</dd></dl>
</div>
<div class="section" id="indexes">
<span id="schema-indexes"></span><h2>Indexes<a class="headerlink" href="#indexes" title="Permalink to this headline">¶</a></h2>
<p>Indexes can be created anonymously (using an auto-generated name <tt class="docutils literal"><span class="pre">ix_<column</span>
<span class="pre">label></span></tt>) for a single column using the inline <tt class="docutils literal"><span class="pre">index</span></tt> keyword on
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>, which also modifies the usage of
<tt class="docutils literal"><span class="pre">unique</span></tt> to apply the uniqueness to the index itself, instead of adding a
separate UNIQUE constraint. For indexes with specific names or which encompass
more than one column, use the <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> construct,
which requires a name.</p>
<p>Below we illustrate a <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> with several
<a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> objects associated. The DDL for “CREATE
INDEX” is issued right after the create statements for the table:</p>
<div class="highlight-python+sql"><div class="highlight"><pre><span class="n">meta</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
<span class="n">mytable</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'mytable'</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
<span class="c"># an indexed column, with index "ix_mytable_col1"</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col1'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="c"># a uniquely indexed column with index "ix_mytable_col2"</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col2'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">unique</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col3'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col4'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col5'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col6'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="p">)</span>
<span class="c"># place an index on col3, col4</span>
<span class="n">Index</span><span class="p">(</span><span class="s">'idx_col34'</span><span class="p">,</span> <span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">col3</span><span class="p">,</span> <span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">col4</span><span class="p">)</span>
<span class="c"># place a unique index on col5, col6</span>
<span class="n">Index</span><span class="p">(</span><span class="s">'myindex'</span><span class="p">,</span> <span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">col5</span><span class="p">,</span> <span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">col6</span><span class="p">,</span> <span class="n">unique</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<a href='#' class='sql_link'>sql</a><span class="n">mytable</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">engine</span><span class="p">)</span>
<div class='popup_sql'>CREATE TABLE mytable (
col1 INTEGER,
col2 INTEGER,
col3 INTEGER,
col4 INTEGER,
col5 INTEGER,
col6 INTEGER
)
CREATE INDEX ix_mytable_col1 ON mytable (col1)
CREATE UNIQUE INDEX ix_mytable_col2 ON mytable (col2)
CREATE UNIQUE INDEX myindex ON mytable (col5, col6)
CREATE INDEX idx_col34 ON mytable (col3, col4)</div></pre></div>
</div>
<p>Note in the example above, the <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> construct is created
externally to the table which it corresponds, using <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
objects directly. <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> also supports
“inline” definition inside the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, using string names to
identify columns:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">meta</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
<span class="n">mytable</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'mytable'</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col1'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col2'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col3'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">'col4'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
<span class="c"># place an index on col1, col2</span>
<span class="n">Index</span><span class="p">(</span><span class="s">'idx_col12'</span><span class="p">,</span> <span class="s">'col1'</span><span class="p">,</span> <span class="s">'col2'</span><span class="p">),</span>
<span class="c"># place a unique index on col3, col4</span>
<span class="n">Index</span><span class="p">(</span><span class="s">'idx_col34'</span><span class="p">,</span> <span class="s">'col3'</span><span class="p">,</span> <span class="s">'col4'</span><span class="p">,</span> <span class="n">unique</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<div class="versionadded">
<p><span>New in version 0.7: </span>Support of “inline” definition inside the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
for <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a>.</p>
</div>
<p>The <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> object also supports its own <tt class="docutils literal"><span class="pre">create()</span></tt> method:</p>
<div class="highlight-python+sql"><div class="highlight"><pre><span class="n">i</span> <span class="o">=</span> <span class="n">Index</span><span class="p">(</span><span class="s">'someindex'</span><span class="p">,</span> <span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">col5</span><span class="p">)</span>
<a href='#' class='sql_link'>sql</a><span class="n">i</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">engine</span><span class="p">)</span>
<div class='popup_sql'>CREATE INDEX someindex ON mytable (col5)</div></pre></div>
</div>
<div class="section" id="functional-indexes">
<span id="schema-indexes-functional"></span><h3>Functional Indexes<a class="headerlink" href="#functional-indexes" title="Permalink to this headline">¶</a></h3>
<p><a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> supports SQL and function expressions, as supported by the
target backend. To create an index against a column using a descending
value, the <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement.desc" title="sqlalchemy.sql.expression.ColumnElement.desc"><tt class="xref py py-meth docutils literal"><span class="pre">ColumnElement.desc()</span></tt></a> modifier may be used:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Index</span>
<span class="n">Index</span><span class="p">(</span><span class="s">'someindex'</span><span class="p">,</span> <span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">somecol</span><span class="o">.</span><span class="n">desc</span><span class="p">())</span></pre></div>
</div>
<p>Or with a backend that supports functional indexes such as Postgresql,
a “case insensitive” index can be created using the <tt class="docutils literal"><span class="pre">lower()</span></tt> function:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">func</span><span class="p">,</span> <span class="n">Index</span>
<span class="n">Index</span><span class="p">(</span><span class="s">'someindex'</span><span class="p">,</span> <span class="n">func</span><span class="o">.</span><span class="n">lower</span><span class="p">(</span><span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">somecol</span><span class="p">))</span></pre></div>
</div>
<div class="versionadded">
<p><span>New in version 0.8: </span><a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> supports SQL expressions and functions
as well as plain columns.</p>
</div>
</div>
</div>
<div class="section" id="index-api">
<h2>Index API<a class="headerlink" href="#index-api" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="sqlalchemy.schema.Index">
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">Index</tt><big>(</big><em>name</em>, <em>*expressions</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Index" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.base.DialectKWArgs</span></tt></a>, <tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.ColumnCollectionMixin</span></tt>, <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.SchemaItem</span></tt></a></p>
<p>A table-level INDEX.</p>
<p>Defines a composite (one or more column) INDEX.</p>
<p>E.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">sometable</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">"sometable"</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">"name"</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">)),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">"address"</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">100</span><span class="p">))</span>
<span class="p">)</span>
<span class="n">Index</span><span class="p">(</span><span class="s">"some_index"</span><span class="p">,</span> <span class="n">sometable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">)</span></pre></div>
</div>
<p>For a no-frills, single column index, adding
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> also supports <tt class="docutils literal"><span class="pre">index=True</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">sometable</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">"sometable"</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">"name"</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">),</span> <span class="n">index</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<p>For a composite index, multiple columns can be specified:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Index</span><span class="p">(</span><span class="s">"some_index"</span><span class="p">,</span> <span class="n">sometable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">sometable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">address</span><span class="p">)</span></pre></div>
</div>
<p>Functional indexes are supported as well, typically by using the
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.func" title="sqlalchemy.sql.expression.func"><tt class="xref py py-data docutils literal"><span class="pre">func</span></tt></a> construct in conjunction with table-bound
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Index</span><span class="p">(</span><span class="s">"some_index"</span><span class="p">,</span> <span class="n">func</span><span class="o">.</span><span class="n">lower</span><span class="p">(</span><span class="n">sometable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">))</span></pre></div>
</div>
<div class="versionadded">
<p><span>New in version 0.8: </span>support for functional and expression-based indexes.</p>
</div>
<p>An <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> can also be manually associated with a <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>,
either through inline declaration or using
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Table.append_constraint" title="sqlalchemy.schema.Table.append_constraint"><tt class="xref py py-meth docutils literal"><span class="pre">Table.append_constraint()</span></tt></a>. When this approach is used, the names
of the indexed columns can be specified as strings:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Table</span><span class="p">(</span><span class="s">"sometable"</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">"name"</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">)),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">"address"</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">100</span><span class="p">)),</span>
<span class="n">Index</span><span class="p">(</span><span class="s">"some_index"</span><span class="p">,</span> <span class="s">"name"</span><span class="p">,</span> <span class="s">"address"</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<p>To support functional or expression-based indexes in this form, the
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.text" title="sqlalchemy.sql.expression.text"><tt class="xref py py-func docutils literal"><span class="pre">text()</span></tt></a> construct may be used:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">text</span>
<span class="n">Table</span><span class="p">(</span><span class="s">"sometable"</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
<span class="n">Column</span><span class="p">(</span><span class="s">"name"</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">)),</span>
<span class="n">Column</span><span class="p">(</span><span class="s">"address"</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">100</span><span class="p">)),</span>
<span class="n">Index</span><span class="p">(</span><span class="s">"some_index"</span><span class="p">,</span> <span class="n">text</span><span class="p">(</span><span class="s">"lower(name)"</span><span class="p">))</span>
<span class="p">)</span></pre></div>
</div>
<div class="versionadded">
<p><span>New in version 0.9.5: </span>the <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.text" title="sqlalchemy.sql.expression.text"><tt class="xref py py-func docutils literal"><span class="pre">text()</span></tt></a> construct may be used to
specify <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> expressions, provided the <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a>
is explicitly associated with the <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="#schema-indexes"><em>Indexes</em></a> - General information on <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a>.</p>
<p><a class="reference internal" href="../dialects/postgresql.html#postgresql-indexes"><em>Postgresql-Specific Index Options</em></a> - PostgreSQL-specific options available for
the <a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> construct.</p>
<p><a class="reference internal" href="../dialects/mysql.html#mysql-indexes"><em>MySQL Specific Index Options</em></a> - MySQL-specific options available for the
<a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> construct.</p>
<p class="last"><a class="reference internal" href="../dialects/mssql.html#mssql-indexes"><em>Clustered Index Support</em></a> - MSSQL-specific options available for the
<a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> construct.</p>
</div>
<dl class="method">
<dt id="sqlalchemy.schema.Index.__init__">
<tt class="descname">__init__</tt><big>(</big><em>name</em>, <em>*expressions</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Index.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct an index object.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.Index.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Index.params.name">¶</a> – The name of the index</li>
<li><span class="target" id="sqlalchemy.schema.Index.params.*expressions"></span><strong>*expressions</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Index.params.*expressions">¶</a> – Column expressions to include in the index. The expressions
are normally instances of <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>, but may also
be arbitrary SQL expressions which ultimately refer to a
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</li>
<li><span class="target" id="sqlalchemy.schema.Index.params.unique"></span><strong>unique=False</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Index.params.unique">¶</a> – Keyword only argument; if True, create a unique index.</li>
<li><span class="target" id="sqlalchemy.schema.Index.params.quote"></span><strong>quote=None</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Index.params.quote">¶</a> – Keyword only argument; whether to apply quoting to the name of
the index. Works in the same manner as that of
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column.params.quote" title="sqlalchemy.schema.Column"><tt class="xref py py-paramref docutils literal"><span class="pre">Column.quote</span></tt></a>.</li>
<li><span class="target" id="sqlalchemy.schema.Index.params.**kw"></span><strong>**kw</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Index.params.**kw">¶</a> – Additional keyword arguments not mentioned above are
dialect specific, and passed in the form
<tt class="docutils literal"><span class="pre"><dialectname>_<argname></span></tt>. See the documentation regarding an
individual dialect at <a class="reference internal" href="../dialects/index.html"><em>Dialects</em></a> for detail on
documented arguments.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="sqlalchemy.schema.Index.argument_for">
<em class="property">classmethod </em><tt class="descname">argument_for</tt><big>(</big><em>dialect_name</em>, <em>argument_name</em>, <em>default</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Index.argument_for" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">argument_for()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>Add a new kind of dialect-specific keyword argument for this class.</p>
<p>E.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Index</span><span class="o">.</span><span class="n">argument_for</span><span class="p">(</span><span class="s">"mydialect"</span><span class="p">,</span> <span class="s">"length"</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
<span class="n">some_index</span> <span class="o">=</span> <span class="n">Index</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span> <span class="s">'b'</span><span class="p">,</span> <span class="n">mydialect_length</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span></pre></div>
</div>
<p>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.argument_for" title="sqlalchemy.sql.base.DialectKWArgs.argument_for"><tt class="xref py py-meth docutils literal"><span class="pre">DialectKWArgs.argument_for()</span></tt></a> method is a per-argument
way adding extra arguments to the
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> dictionary. This
dictionary provides a list of argument names accepted by various
schema-level constructs on behalf of a dialect.</p>
<p>New dialects should typically specify this dictionary all at once as a
data member of the dialect class. The use case for ad-hoc addition of
argument names is typically for end-user code that is also using
a custom compilation scheme which consumes the additional arguments.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="sqlalchemy.schema.Index.argument_for.params.dialect_name"></span><strong>dialect_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Index.argument_for.params.dialect_name">¶</a> – name of a dialect. The dialect must be
locatable, else a <tt class="xref py py-class docutils literal"><span class="pre">NoSuchModuleError</span></tt> is raised. The
dialect must also include an existing
<a class="reference internal" href="internals.html#sqlalchemy.engine.default.DefaultDialect.construct_arguments" title="sqlalchemy.engine.default.DefaultDialect.construct_arguments"><tt class="xref py py-attr docutils literal"><span class="pre">DefaultDialect.construct_arguments</span></tt></a> collection, indicating
that it participates in the keyword-argument validation and default
system, else <tt class="xref py py-class docutils literal"><span class="pre">ArgumentError</span></tt> is raised. If the dialect does
not include this collection, then any keyword argument can be
specified on behalf of this dialect already. All dialects packaged
within SQLAlchemy include this collection, however for third party
dialects, support may vary.</li>
<li><span class="target" id="sqlalchemy.schema.Index.argument_for.params.argument_name"></span><strong>argument_name</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Index.argument_for.params.argument_name">¶</a> – name of the parameter.</li>
<li><span class="target" id="sqlalchemy.schema.Index.argument_for.params.default"></span><strong>default</strong><a class="paramlink headerlink reference internal" href="#sqlalchemy.schema.Index.argument_for.params.default">¶</a> – default value of the parameter.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span>New in version 0.9.4.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.Index.bind">
<tt class="descname">bind</tt><a class="headerlink" href="#sqlalchemy.schema.Index.bind" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the connectable associated with this Index.</p>
</dd></dl>
<dl class="method">
<dt id="sqlalchemy.schema.Index.create">
<tt class="descname">create</tt><big>(</big><em>bind=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Index.create" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a <tt class="docutils literal"><span class="pre">CREATE</span></tt> statement for this
<a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a>, using the given <a class="reference internal" href="connections.html#sqlalchemy.engine.Connectable" title="sqlalchemy.engine.Connectable"><tt class="xref py py-class docutils literal"><span class="pre">Connectable</span></tt></a>
for connectivity.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData.create_all" title="sqlalchemy.schema.MetaData.create_all"><tt class="xref py py-meth docutils literal"><span class="pre">MetaData.create_all()</span></tt></a>.</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.Index.dialect_kwargs">
<tt class="descname">dialect_kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.Index.dialect_kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>The arguments are present here in their original <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt>
format. Only arguments that were actually passed are included;
unlike the <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> collection, which
contains all options known by this dialect including defaults.</p>
<p>The collection is also writable; keys are accepted of the
form <tt class="docutils literal"><span class="pre"><dialect>_<kwarg></span></tt> where the value will be assembled
into the list of options.</p>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="versionchanged">
<p><span>Changed in version 0.9.4: </span>The <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>
collection is now writable.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_options</span></tt></a> - nested dictionary form</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.Index.dialect_options">
<tt class="descname">dialect_options</tt><a class="headerlink" href="#sqlalchemy.schema.Index.dialect_options" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_options" title="sqlalchemy.sql.base.DialectKWArgs.dialect_options"><tt class="xref py py-attr docutils literal"><span class="pre">dialect_options</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A collection of keyword arguments specified as dialect-specific
options to this construct.</p>
<p>This is a two-level nested registry, keyed to <tt class="docutils literal"><span class="pre"><dialect_name></span></tt>
and <tt class="docutils literal"><span class="pre"><argument_name></span></tt>. For example, the <tt class="docutils literal"><span class="pre">postgresql_where</span></tt>
argument would be locatable as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">arg</span> <span class="o">=</span> <span class="n">my_object</span><span class="o">.</span><span class="n">dialect_options</span><span class="p">[</span><span class="s">'postgresql'</span><span class="p">][</span><span class="s">'where'</span><span class="p">]</span></pre></div>
</div>
<div class="versionadded">
<p><span>New in version 0.9.2.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a> - flat dictionary form</p>
</div>
</dd></dl>
<dl class="method">
<dt id="sqlalchemy.schema.Index.drop">
<tt class="descname">drop</tt><big>(</big><em>bind=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Index.drop" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a <tt class="docutils literal"><span class="pre">DROP</span></tt> statement for this
<a class="reference internal" href="#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a>, using the given <a class="reference internal" href="connections.html#sqlalchemy.engine.Connectable" title="sqlalchemy.engine.Connectable"><tt class="xref py py-class docutils literal"><span class="pre">Connectable</span></tt></a>
for connectivity.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData.drop_all" title="sqlalchemy.schema.MetaData.drop_all"><tt class="xref py py-meth docutils literal"><span class="pre">MetaData.drop_all()</span></tt></a>.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="sqlalchemy.schema.Index.get_children">
<tt class="descname">get_children</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Index.get_children" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.get_children" title="sqlalchemy.schema.SchemaItem.get_children"><tt class="xref py py-meth docutils literal"><span class="pre">get_children()</span></tt></a> <em>method of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>used to allow SchemaVisitor access</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.Index.info">
<tt class="descname">info</tt><a class="headerlink" href="#sqlalchemy.schema.Index.info" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.info" title="sqlalchemy.schema.SchemaItem.info"><tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Info dictionary associated with the object, allowing user-defined
data to be associated with this <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a>.</p>
<p>The dictionary is automatically generated when first accessed.
It can also be specified in the constructor of some objects,
such as <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> and <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.Index.kwargs">
<tt class="descname">kwargs</tt><a class="headerlink" href="#sqlalchemy.schema.Index.kwargs" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.kwargs" title="sqlalchemy.sql.base.DialectKWArgs.kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">kwargs</span></tt></a> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs" title="sqlalchemy.sql.base.DialectKWArgs"><tt class="xref py py-class docutils literal"><span class="pre">DialectKWArgs</span></tt></a></div>
<p>A synonym for <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs" title="sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs"><tt class="xref py py-attr docutils literal"><span class="pre">DialectKWArgs.dialect_kwargs</span></tt></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sqlalchemy.schema.Index.quote">
<tt class="descname">quote</tt><a class="headerlink" href="#sqlalchemy.schema.Index.quote" title="Permalink to this definition">¶</a></dt>
<dd><div class="inherited-member container">
<em>inherited from the</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem.quote" title="sqlalchemy.schema.SchemaItem.quote"><tt class="xref py py-attr docutils literal"><span class="pre">quote</span></tt></a> <em>attribute of</em> <a class="reference internal" href="metadata.html#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
<p>Return the value of the <tt class="docutils literal"><span class="pre">quote</span></tt> flag passed
to this schema object, for those schema items which
have a <tt class="docutils literal"><span class="pre">name</span></tt> field.</p>
<div class="deprecated">
<p><span>Deprecated since version 0.9: </span>Use <tt class="docutils literal"><span class="pre"><obj>.name.quote</span></tt></p>
</div>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
<div id="docs-bottom-navigation" class="docs-navigation-links">
Previous:
<a href="defaults.html" title="previous chapter">Column Insert/Update Defaults</a>
Next:
<a href="ddl.html" title="next chapter">Customizing DDL</a>
<div id="docs-copyright">
© <a href="../copyright.html">Copyright</a> 2007-2014, the SQLAlchemy authors and contributors.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2b1.
</div>
</div>
</div>
</body>
</html>
|