Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQLAlchemy Core-Python中使用Table()的最大列数_Python_Mysql_Sqlalchemy - Fatal编程技术网

SQLAlchemy Core-Python中使用Table()的最大列数

SQLAlchemy Core-Python中使用Table()的最大列数,python,mysql,sqlalchemy,Python,Mysql,Sqlalchemy,我正在使用Python中的SQLAlchemy核心构建MySQL表。我使用Table()函数如下: 如您所见,每列都作为函数的参数给出。问题是Python函数最多只能处理255个参数,但我需要构建一个包含400个参数的表。有没有办法绕过Python中的参数限制?或者我可以使用另一个函数来构建表?我尝试将列/参数作为列表提交,但这不起作用 谢谢大家! 编辑: 我试图使用与SQLAlchemy核心教程中相同的Table()格式。例如: addresses = Table('addresses',

我正在使用Python中的SQLAlchemy核心构建MySQL表。我使用Table()函数如下:

如您所见,每列都作为函数的参数给出。问题是Python函数最多只能处理255个参数,但我需要构建一个包含400个参数的表。有没有办法绕过Python中的参数限制?或者我可以使用另一个函数来构建表?我尝试将列/参数作为列表提交,但这不起作用

谢谢大家!

编辑: 我试图使用与SQLAlchemy核心教程中相同的Table()格式。例如:

addresses = Table('addresses', metadata,
Column('id', Integer, primary_key=True),
Column('user_id', None, nullable=False),
Column('email_address', String, nullable=False))

显然,使用Table()将创建三列。但是,我想再创建397(不同)列,但无法创建,因为Table()只接受255个参数。有没有办法解决这个问题?

这似乎很好用

你到底有什么问题

编辑

from sqlalchemy import Table, Column, Integer, String, MetaData
metadata = MetaData()
hello =  [Column('x{}'.format(i), String, nullable=False) for i in range(1000)]
t = Table('t', metadata, *hello)
print t.__dict__
print t.__dict__.get("_columns")
#{'schema': None, '_columns': <sqlalchemy.sql.base.ColumnCollection object at 0x026C68A0>, 'name': 't', 'dispatch': <sqlalchemy.event.base.DDLEventsDispatch object at 0x02133B70>, 'indexes': set([]), 'foreign_keys': set([]), 'columns': <sqlalchemy.sql.base.ImmutableColumnCollection object at 0x02717300>, '_prefixes': [], '_extra_dependencies': set([]), 'fullname': 't', 'metadata': MetaData(bind=None), 'implicit_returning': True, 'constraints': set([PrimaryKeyConstraint()]), 'primary_key': PrimaryKeyConstraint()}
#['t.x0', 't.x1', 't.x2', 't.x3', 't.x4', 't.x5', 't.x6', 't.x7', 't.x8', 't.x9', 't.x10', 't.x11', 't.x12', 't.x13', 't.x14', 't.x15', 't.x16', 't.x17', 't.x18', 't.x19', 't.x20', 't.x21', 't.x22', 't.x23', 't.x24', 't.x25', 't.x26', 't.x27', 't.x28', 't.x29', 't.x30', 't.x31', 't.x32', 't.x33', 't.x34', 't.x35', 't.x36', 't.x37', 't.x38', 't.x39', 't.x40', 't.x41', 't.x42', 't.x43', 't.x44', 't.x45', 't.x46', 't.x47', 't.x48', 't.x49', 't.x50', 't.x51', 't.x52', 't.x53', 't.x54', 't.x55', 't.x56', 't.x57', 't.x58', 't.x59', 't.x60', 't.x61', 't.x62', 't.x63', 't.x64', 't.x65', 't.x66', 't.x67', 't.x68', 't.x69', 't.x70', 't.x71', 't.x72', 't.x73', 't.x74', 't.x75', 't.x76', 't.x77', 't.x78', 't.x79', 't.x80', 't.x81', 't.x82', 't.x83', 't.x84', 't.x85', 't.x86', 't.x87', 't.x88', 't.x89', 't.x90', 't.x91', 't.x92', 't.x93', 't.x94', 't.x95', 't.x96', 't.x97', 't.x98', 't.x99', 't.x100', 't.x101', 't.x102', 't.x103', 't.x104', 't.x105', 't.x106', 't.x107', 't.x108', 't.x109', 't.x110', 't.x111', 't.x112', 't.x113', 't.x114', 't.x115', 't.x116', 't.x117', 't.x118', 't.x119', 't.x120', 't.x121', 't.x122', 't.x123', 't.x124', 't.x125', 't.x126', 't.x127', 't.x128', 't.x129', 't.x130', 't.x131', 't.x132', 't.x133', 't.x134', 't.x135', 't.x136', 't.x137', 't.x138', 't.x139', 't.x140', 't.x141', 't.x142', 't.x143', 't.x144', 't.x145', 't.x146', 't.x147', 't.x148', 't.x149', 't.x150', 't.x151', 't.x152', 't.x153', 't.x154', 't.x155', 't.x156', 't.x157', 't.x158', 't.x159', 't.x160', 't.x161', 't.x162', 't.x163', 't.x164', 't.x165', 't.x166', 't.x167', 't.x168', 't.x169', 't.x170', 't.x171', 't.x172', 't.x173', 't.x174', 't.x175', 't.x176', 't.x177', 't.x178', 't.x179', 't.x180', 't.x181', 't.x182', 't.x183', 't.x184', 't.x185', 't.x186', 't.x187', 't.x188', 't.x189', 't.x190', 't.x191', 't.x192', 't.x193', 't.x194', 't.x195', 't.x196', 't.x197', 't.x198', 't.x199', 't.x200', 't.x201', 't.x202', 't.x203', 't.x204', 't.x205', 't.x206', 't.x207', 't.x208', 't.x209', 't.x210', 't.x211', 't.x212', 't.x213', 't.x214', 't.x215', 't.x216', 't.x217', 't.x218', 't.x219', 't.x220', 't.x221', 't.x222', 't.x223', 't.x224', 't.x225', 't.x226', 't.x227', 't.x228', 't.x229', 't.x230', 't.x231', 't.x232', 't.x233', 't.x234', 't.x235', 't.x236', 't.x237', 't.x238', 't.x239', 't.x240', 't.x241', 't.x242', 't.x243', 't.x244', 't.x245', 't.x246', 't.x247', 't.x248', 't.x249', 't.x250', 't.x251', 't.x252', 't.x253', 't.x254', 't.x255', 't.x256', 't.x257', 't.x258', 't.x259', 't.x260', 't.x261', 't.x262', 't.x263', 't.x264', 't.x265', 't.x266', 't.x267', 't.x268', 't.x269', 't.x270', 't.x271', 't.x272', 't.x273', 't.x274', 't.x275', 't.x276', 't.x277', 't.x278', 't.x279', 't.x280', 't.x281', 't.x282', 't.x283', 't.x284', 't.x285', 't.x286', 't.x287', 't.x288', 't.x289', 't.x290', 't.x291', 't.x292', 't.x293', 't.x294', 't.x295', 't.x296', 't.x297', 't.x298', 't.x299'.....]
从sqlalchemy导入表、列、整数、字符串、元数据
元数据=元数据()
hello=[Column('x{})。范围(1000)内的i的格式(i),字符串,null=False)]
t=表('t',元数据,*hello)
打印文本__
打印t.。uuu dict_uuuu.get(“u列”)
#{'schema':无,'u列':,'name':'t','dispatch':,'index':set([]),'foreign_key':set([]),'columns':,'u prefixes':[],'u extra_dependenciencies':set([]),'fullname':'t','metadata':元数据(bind=None),'implicit_returning':True,'constraints':set([PrimaryKeyConstraint()),'PrimaryKeyConstraint()),'PrimaryKeyConstraint','primaryKeyConstra
#“t.x0”、“t.x0”、“t.x0”、“t.x0”、“t.x0”、“t.x0”、“t.x6”、“t.x7”、“t.x7”、“t.x0”、“t.x0”、“t.x0”、“t.x0”、“t.x0”、“t.x0”、“t.x0”、“t.x0”、“t.x0”、“t.X”、“t.X”、“t.x0”、“t.x0”、“t.x8”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.x7”、“t.“t.x38”,“t.x39”“t.x44”、“t.x44”、“t.x44”、“t.x44”、“t.x44”、“t.x44”、“t.x45”、“t.x46”、“t.x46”、“t.x46”、“t.x47”、“t.x40”、“t.x40”、“t.x40”、“t.x40”、“t.x40”、“t.x40”、“t.x40”、“t.x44”、“t.x44”、“t.x43”、“t.x44”、“t.x47”、“t.x46”、“t.x46”、“t.x47”、“t.x46”、“t.x47”、“t.x44”、“t.x46”、“t.x46”、“t””、“t.x47”、“t.x47”、“t.x46”、“t.x46”、“t.x47”、“t.x46”、“t.x47”、“t.x46”、“t.7”、“t.x47”、“t.x47”、“t.7”、“t.7”、“t.7”、“t.7”、“t.x47”、“t.x46”、“t.7',t.x78、t.x79、t.x80、t.x81、t.x82、t.x83、t.x84、t.x85、t.x86、t.x87、t.x88、t.x89、t.x90、t.x91、t.x92、t.x93、t.x94、t.x95、t.x96、t.x97、t.x98、t.x99、t.x100、t.x101、t.x102、t.x103、t.x103、t.x104、t.x105、t.x106、t.x106、t.x107、t.x108、t.x108、t.x110、t.x111、t.x111、t.x1015、t.x116、t.x117、t.x118、t.x119、t.x120、t.x121、t.x122、t.x123、t.x124、t.x125、t.x126、t.x127、t.x128、t.x129、t.x130、t.x131、t.x132、t.x133、t.x134、t.x135、t.x136、t.x137、t.x138、t.x139、t.x140、t.x141、t.x142、t.x143、t.x144、t.x148、t.x145、t.x148、t.x14950',t.x151',t.x152',t.x153',t.x154',t.x155',t.x156',t.x157',t.x158',t.x159',t.x160',t.x161',t.x162',t.x163',t.x164',t.x165',t.x166',t.x167',t.x168',t.x169',t.x170',t.x171',t.x172',t.x173',t.x174',t.x175',t.x176',t.x177',t.x178',t.x178',t.x180',t.x183185',t.x186',t.x187',t.x188',t.x189',t.x190',t.x191',t.x192',t.x193',t.x194',t.x195',t.x196',t.x197',t.x198',t.x199',t.x200',t.x201',t.x202',t.x203',t.x204',t.x205',t.x206',t.x207',t.x208',t.x209',t.x210',t.x211',t.x212',t.x213',t.x214',t.x201',t.x218',t.x218',t.x219'。x220、t.x221、t.x222、t.x223、t.x224、t.x225、t.x226、t.x227、t.x228、t.x229、t.x230、t.x231、t.x232、t.x233、t.x234、t.x235、t.x236、t.x237、t.x238、t.x239、t.x240、t.x241、t.x242、t.x243、t.x244、t.x245、t.x246、t.x247、t.x248、t.x245、t.x249、t.x251、t.x254、t.x252、t.x254、t.x250、t.x254、t.x254.x255、t.x256、t.x257、t.x258、t.x259、t.x260、t.x261、t.x262、t.x263、t.x264、t.x265、t.x266、t.x267、t.x268、t.x269、t.x270、t.x271、t.x272、t.x273、t.x274、t.x275、t.x276、t.x277、t.x278、t.x279、t.x282、t.x280、t.x281、t.x282、t.x283、t.x284、t.x287、t.x289、t.x289、t.x289t、 x290',t.x291',t.x292',t.x293',t.x294',t.x295',t.x296',t.x297',t.x298',t.x299'.]
在上面的例子中,我使用列表理解来创建1000列,并将其传递到我的表函数中


另外,需要注意的是,一个包含400列的表并不一定是个好主意,您可能应该计划如何有效地创建多个表,而不是一个大表。

我基本上是将所有列都放在列表中,并在列表中加一个星号。我不太理解您的解决方案。您在哪里定义数据类型、可为null等?如果这是一个基本问题,很抱歉,我对Python非常陌生。您是否可以利用我上面使用的Table()格式?我使用了与您相同的精确导入进行了修改。基本上,您可以做的是放置所有列()进入列表,并将该列表分配给表函数。在上面的示例中,我使用列表理解创建1000列,并将其传递到我的表函数中。您必须将每个列逐个定义到列表中。我想我现在明白了。当参数更改时,我必须提供单独的列表。因此,对于我的“String,nullable=False”列我将创建“hello”列表,但对于我的“Integer”列,我必须提供另一个列表。这是否正确?否,您将创建整个列表。
[列('column1',Integer,Primary…),列('column2',String,nullable=True,…)]
在示例中,我刚刚使用列表理解快速创建了它。您只需手动创建一个非常大的列表即可。