我创建了一个新的SQL web2py数据库,如下所述...但是当我尝试保存它时,它会出现语法错误。如何将其保存在web2py上并将其用于我的网页..
dbOBJECT = SQLDB("sqlite://dbOBJECT.db")
"""
Table definition
"""
dbOBJECT.define_table("USER DETAILS",
SQLField("UID_GET ID", dbOBJECT.GET ID),
SQLField("USERNAME_USER", dbOBJECT.USER),
SQLField("ROLE ID_ROLES", dbOBJECT.ROLES),
SQLField("FIRST NAME", "VARCHAR", length=100, notnull=True, default=None),
SQLField("LAST NAME", "VARCHAR", length=100, notnull=True, default=None),
SQLField("DATE OF BIRTH", "DATE", notnull=True, default=None),
SQLField("GID_GENDER", dbOBJECT.GENDER),
SQLField("BRANCH ID_BRANCH", dbOBJECT.BRANCH),
SQLField("COUNTRY ID_COUNTRY", dbOBJECT.COUNTRY),
SQLField("WORKING ID_WORKING", dbOBJECT.WORKING),
SQLField("WORKED ID_WORKED ", dbOBJECT.WORKED ))
"""
Table definition
"""
dbOBJECT.define_table("GET ID",
SQLField("UID", "INTEGER", notnull=True, default=None),
SQLField("USERNAME_USER", dbOBJECT.USER),
SQLField("new field", "INTEGER", notnull=True, default=None))
"""
Table definition
"""
dbOBJECT.define_table("USER",
SQLField("USERNAME", "VARCHAR", length=100, notnull=True, default=None),
SQLField("EMAIL", "VARCHAR", length=100, default=None),
SQLField("PASSWORD", "VARCHAR", length=20, notnull=True, default=None),
SQLField("ROLE ID_ROLES", dbOBJECT.ROLES))
"""
Table definition
"""
dbOBJECT.define_table("COUNTRY",
SQLField("COUNTRY ID", "VARCHAR", length=50, notnull=True, default=None),
SQLField("COUNTRY", "VARCHAR", length=50, notnull=True, default=None),
SQLField("CITY ID_CITY", dbOBJECT.CITY))
"""
Table definition
"""
dbOBJECT.define_table("ROLES",
SQLField("ROLE ID", "INTEGER", notnull=True, default=None),
SQLField("ROLE NAME", "VARCHAR", length=100, notnull=True, default=None))
"""
Table definition
"""
dbOBJECT.define_table("WORKED ",
SQLField("WORKED ID", "INTEGER", notnull=True, default=None),
SQLField("PLACE ID_COMPANY", dbOBJECT.COMPANY),
SQLField("DESIGNATION ID_DESIGNATION", dbOBJECT.DESIGNATION))
"""
Table definition
"""
dbOBJECT.define_table("CITY",
SQLField("CITY ID", "INTEGER", notnull=True, default=None),
SQLField("CITY", "VARCHAR", length=50, notnull=True, default=None))
"""
Table definition
"""
dbOBJECT.define_table("GENDER",
SQLField("GID", "INTEGER", notnull=True, default=None),
SQLField("GENDER", "VARCHAR", length=10, notnull=True, default=None))
"""
Table definition
"""
dbOBJECT.define_table("BRANCH",
SQLField("BRANCH ID", "INTEGER", notnull=True, default=None),
SQLField("BRANCH", "VARCHAR", length=50, notnull=True, default=None))
"""
Table definition
"""
dbOBJECT.define_table("WORKING",
SQLField("WORKING ID", "INTEGER", notnull=True, default=None),
SQLField("PLACE ID_COMPANY", dbOBJECT.COMPANY),
SQLField("DESIGNATION ID_DESIGNATION", dbOBJECT.DESIGNATION))
"""
Table definition
"""
dbOBJECT.define_table("USER CONTACT",
SQLField("MOBILE NUMBER", "INTEGER", notnull=True, default=None),
SQLField("FACEBOOK LINK", "VARCHAR", length=50, default=None),
SQLField("TWITTER LINK", "VARCHAR", length=50, default=None),
SQLField("LINKEDIN", "VARCHAR", length=50, default=None),
SQLField("UID_GET ID", dbOBJECT.GET ID))
"""
Table definition
"""
dbOBJECT.define_table("COMPANY",
SQLField("PLACE ID", "INTEGER", notnull=True, default=None),
SQLField("PLACE", "VARCHAR", length=100, notnull=True, default=None))
"""
Table definition
"""
dbOBJECT.define_table("DESIGNATION",
SQLField("DESIGNATION ID", "INTEGER", notnull=True, default=None),
SQLField("DESIGNATION", "VARCHAR", length=50, notnull=True, default=None))
"""
Relations between tables (remove fields you don't need from requires)
"""
dbOBJECT.USER DETAILS.UID_GET ID.requires=IS_IN_DB(dbOBJECT, 'GET ID.id','GET ID.UID','GET ID.USERNAME_USER','GET ID.new field')
dbOBJECT.USER DETAILS.USERNAME_USER.requires=IS_IN_DB(dbOBJECT, 'USER.id','USER.USERNAME','USER.EMAIL','USER.PASSWORD','USER.ROLE ID_ROLES')
dbOBJECT.USER DETAILS.ROLE ID_ROLES.requires=IS_IN_DB(dbOBJECT, 'ROLES.id','ROLES.ROLE ID','ROLES.ROLE NAME')
dbOBJECT.USER DETAILS.GID_GENDER.requires=IS_IN_DB(dbOBJECT, 'GENDER.id','GENDER.GID','GENDER.GENDER')
dbOBJECT.USER DETAILS.BRANCH ID_BRANCH.requires=IS_IN_DB(dbOBJECT, 'BRANCH.id','BRANCH.BRANCH ID','BRANCH.BRANCH')
dbOBJECT.USER DETAILS.COUNTRY ID_COUNTRY.requires=IS_IN_DB(dbOBJECT, 'COUNTRY.id','COUNTRY.COUNTRY ID','COUNTRY.COUNTRY','COUNTRY.CITY ID_CITY')
dbOBJECT.USER DETAILS.WORKING ID_WORKING.requires=IS_IN_DB(dbOBJECT, 'WORKING.id','WORKING.WORKING ID','WORKING.PLACE ID_COMPANY','WORKING.DESIGNATION ID_DESIGNATION')
dbOBJECT.USER DETAILS.WORKED ID_WORKED .requires=IS_IN_DB(dbOBJECT, 'WORKED .id','WORKED .WORKED ID','WORKED .PLACE ID_COMPANY','WORKED .DESIGNATION ID_DESIGNATION')
dbOBJECT.GET ID.USERNAME_USER.requires=IS_IN_DB(dbOBJECT, 'USER.id','USER.USERNAME','USER.EMAIL','USER.PASSWORD','USER.ROLE ID_ROLES')
dbOBJECT.USER.ROLE ID_ROLES.requires=IS_IN_DB(dbOBJECT, 'ROLES.id','ROLES.ROLE ID','ROLES.ROLE NAME')
dbOBJECT.COUNTRY.CITY ID_CITY.requires=IS_IN_DB(dbOBJECT, 'CITY.id','CITY.CITY ID','CITY.CITY')
dbOBJECT.WORKED .PLACE ID_COMPANY.requires=IS_IN_DB(dbOBJECT, 'COMPANY.id','COMPANY.PLACE ID','COMPANY.PLACE')
dbOBJECT.WORKED .DESIGNATION ID_DESIGNATION.requires=IS_IN_DB(dbOBJECT, 'DESIGNATION.id','DESIGNATION.DESIGNATION ID','DESIGNATION.DESIGNATION')
dbOBJECT.WORKING.PLACE ID_COMPANY.requires=IS_IN_DB(dbOBJECT, 'COMPANY.id','COMPANY.PLACE ID','COMPANY.PLACE')
dbOBJECT.WORKING.DESIGNATION ID_DESIGNATION.requires=IS_IN_DB(dbOBJECT, 'DESIGNATION.id','DESIGNATION.DESIGNATION ID','DESIGNATION.DESIGNATION')
dbOBJECT.USER CONTACT.UID_GET ID.requires=IS_IN_DB(dbOBJECT, 'GET ID.id','GET ID.UID','GET ID.USERNAME_USER','GET ID.new field')
欢迎任何帮助...... 附:只是一个初学者..
答案 0 :(得分:1)
首先,表名和字段名必须是有效的Python标识符,因此它们不能包含空格。相反,如果使用下划线,它们将自动转换为SQLFORM标签中的空格。您还可以为Field()
构造函数指定单独的“label”参数,以便在不喜欢默认标签时为表单和网格创建标签。
其次,字段类型应该是小写的,并且没有“varchar”字段类型 - 而应该是“string”(尽管“string”是默认值,因此不是必需的)。
最后,SQLDB
已被弃用,而DAL
已被弃用,SQLField
已被弃用,转而使用Field
。
我强烈建议您在继续之前阅读DAL
documentation。