Search code examples
pythonpython-3.xdbf

'FieldMissingError' when trying to write row


I keep getting a FieldMissingError on a field ('severa_id') of which I am sure that it exists. I've checked ver_33.py which shows that the Exception triggers if the field is not in self._meta.fields.

table._meta.fields shows the field being there:

print(table._meta.fields)
>>> 
['proj_code', 'severa_id', 'rec_id', 'ext_key']
>>> 

This is the code I'm trying:

table = dbf.Table(path_to_dbf)

table.open()

for row in dbf.Process(table):
    for project in projects:
        if str(row.proj_code)[0:4] == project["ProjectNumber"]:
            row.write_record(severa_id=project["GUID"])

I've also tried these methods of setting the field:

row.severa_id = project["ProjectNumber"]
#row.write()
row.write_record()

Lastly, I've also tried setting each of the other fields (with a random string) which results in the same error.

EDIT: I am using the dbf module (https://pypi.python.org/pypi/dbf/0.96.005)

EDIT: The original traceback:

Traceback (most recent call last):
File "<string>", line 420, in run_nodebug
File "C:\Users\Alexander\Documents\update_projecten\update_dbf.py", line 58, in <module>
row.write()
File "C:\Users\Alexander\Envs\vfp\lib\site-packages\dbf\ver_33.py", line    2451, in __getattr__
raise FieldMissingError(name)
dbf.ver_33.FieldMissingError: 'write:  no such field in table'

EDIT: The final version of the script that worked. Note not using Process and indicating in dbf.write the row and field to be written.

table = dbf.Table(path_to_dbf)
table.open()

for row in table:
    for project in projects:
        if str(row.proj_code)[0:4] == project["ProjectNumber"]:
           dbf.write(row, severa_id=project["GUID"])

Solution

  • write_record no longer exists as a row method, so the error you are seeing is probably stating that write_record is not a field.

    Instead, try:

    dbf.write(severa_id=project['GUID'])