0

I am trying to find a way to make all my ids start with the current year so 21 for example this is an id right now: 4321 and I want to turn this into 214321 so it's easier to find stuff by year. Is there any way I could do this without manually adding a 21 in front of where I print my id each time? this is how my ids are made and I tried to concatenate 21 to the id but it gives me an error.

id = db.Column(db.Integer, primary_key=True)
id = "21" + id
print(id)

This is the error I'm getting:

msr could not assemble any primary key columns for mapped table 'msr' 

(msr is the name of my database table)

Nelewout
  • 6,281
  • 3
  • 29
  • 39
  • "so it's easier to find stuff by year" - why not create a new column `year_add` that tracks the year in which the record was added? Or a `date_add` column that stores a datetime-equivalent from which you can also parse this info? – Nelewout Jul 26 '21 at 12:39
  • Does this answer your question? [Auto-incrementing attribute with custom logic in SQLAlchemy](https://stackoverflow.com/questions/1038126/auto-incrementing-attribute-with-custom-logic-in-sqlalchemy) – rfkortekaas Jul 26 '21 at 18:52
  • yeah i might do that instead. @rfkortekaas the link you sent me just replaces the value of the id if it is ever equal to NULL so this doesn't realy help me in the situation i'm in but thanks for taking the time. – matthew fabrie Jul 28 '21 at 16:16

1 Answers1

0

im not that familiar with database tables but could it be that you are trying to add a string to an integer.