horilla-opensource / horilla

Horilla is a free and open source HR software.
https://www.horilla.com/
GNU Lesser General Public License v2.1
154 stars 102 forks source link

Fail to run python3 manage,py migrate #305

Open MrcellSbst opened 2 weeks ago

MrcellSbst commented 2 weeks ago

duplicate column name: installment_amount

Environment: Ubuntu 22.04 Django 4.2.11 Python 3.10.12 PostgreSql

Error log: python3 manage.py migrate Operations to perform: Apply all migrations: admin, asset, attendance, auditlog, auth, base, biometric, contenttypes, django_apscheduler, employee, helpdesk, horilla_audit, horilla_automations, horilla_documents, horilla_views, leave, notifications, offboarding, onboarding, payroll, pms, recruitment, sessions Running migrations: Applying payroll.0002_loanaccount_installment_amount_and_more...Traceback (most recent call last): File "/root/myenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) File "/root/myenv/lib/python3.10/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute return super().execute(query, params) sqlite3.OperationalError: duplicate column name: installment_amount

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/root/horilla/manage.py", line 22, in main() File "/root/horilla/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/root/myenv/lib/python3.10/site-packages/django/core/management/init.py", line 442, in execute_from_command_line utility.execute() File "/root/myenv/lib/python3.10/site-packages/django/core/management/init.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/root/myenv/lib/python3.10/site-packages/django/core/management/base.py", line 412, in run_from_argv self.execute(*args, cmd_options) File "/root/myenv/lib/python3.10/site-packages/django/core/management/base.py", line 458, in execute output = self.handle(*args, *options) File "/root/myenv/lib/python3.10/site-packages/django/core/management/base.py", line 106, in wrapper res = handle_func(args, kwargs) File "/root/myenv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 356, in handle post_migrate_state = executor.migrate( File "/root/myenv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 135, in migrate state = self._migrate_all_forwards( File "/root/myenv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards state = self.apply_migration( File "/root/myenv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 252, in apply_migration state = migration.apply(state, schema_editor) File "/root/myenv/lib/python3.10/site-packages/django/db/migrations/migration.py", line 132, in apply operation.database_forwards( File "/root/myenv/lib/python3.10/site-packages/django/db/migrations/operations/fields.py", line 108, in database_forwards schema_editor.add_field( File "/root/myenv/lib/python3.10/site-packages/django/db/backends/sqlite3/schema.py", line 402, in add_field super().add_field(model, field) File "/root/myenv/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 713, in add_field self.execute(sql, params) File "/root/myenv/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 201, in execute cursor.execute(sql, params) File "/root/myenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 102, in execute return super().execute(sql, params) File "/root/myenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute return self._execute_with_wrappers( File "/root/myenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers return executor(sql, params, many, context) File "/root/myenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute with self.db.wrap_database_errors: File "/root/myenv/lib/python3.10/site-packages/django/db/utils.py", line 91, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "/root/myenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) File "/root/myenv/lib/python3.10/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute return super().execute(query, params) django.db.utils.OperationalError: duplicate column name: installment_amount

horilla-opensource commented 2 weeks ago

Hi @MrcellSbst , Can you confirm the database connection in the settings? In your environment you have mentioned about using the postgresql, but from the log its being shown as sqlite3.

With Regards, Team Horilla

MrcellSbst commented 2 weeks ago

i'm pulling the newest update, when i tried to run server it told me to applied new migration so run python3 manage.py makemigrations and migrate, but i got this error. the database is in the same server

horilla-opensource commented 2 weeks ago

If the database is correct and the issue still persists, in the latest migration file of the payroll module, comment out the line adding the new column installment_amount and run the migrate command without running the makemigrations commands.

You can find a similar line : ('installment_amount', models.FloatField(blank=True, null=True, verbose_name='installment Amount')), Comment this line and run the migrate command

MrcellSbst commented 2 weeks ago

still failed now it different table

this is my db connection setting: image

horilla-opensource commented 2 weeks ago

Hi @MrcellSbst , Please do the same method for the other duplicate column. Basically when there is already a column in the database, on the makemigrations command the duplicate column shouldn't come inside it. It's strange to happen like this.