Laravel Migration - Data type also changes when renaming column - laravel-5.8

I want to rename the column in database using migration, but when i tried it, the datatype also changes. How to rename column without changing the data type.
The current name of the column in the database is
payment_amount_cash and its type is double(10,2)
I tried
$table->renameColumn('payment_amount_cash', 'payment_amount_full')->comment('Advanced payment')->default("0.00");
to rename the column. Then after migration, the name was changed but the data type was also changed from double(10,2) to only double thus, making the default value change from 0.00 to 0.
I also tried to change the data type after the schema of renaming the column.
$table->renameColumn('payment_amount_cash', 'payment_amount_full')->comment('Advanced payment')->default("0.00");
$table->double('payment_amount_full', 10,2)->change();
but this one gives me error upon migration.
Doctrine\DBAL\DBALException : Unknown column type "double" requested.
Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType().
You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap().
If this error occurs during database introspection then you might have forgotten to register all database types for a Doctrine Type.
Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes().
If the type name is empty you might have a problem with the cache or forgot some mapping information.
With this, I just want to know how to rename the column without affecting the data type. After migration, I would like to retain the data type of the column I just changed the name.

I learned that there is an issue in Schema regarding the enum and still in discussion until now.
I just used the other way to update the datatype of the column.
DB::statement('ALTER TABLE reservations MODIFY COLUMN payment_amount_full double(10,2)');
and this works for me. If there are other ways on how to do this, please let me know. Thanks.

Related

Laravel - Automatically store history in column

Can anyone help me to automatically save the history of all changed columns in a model to a history column in the same table as JSON format with column(s) name, original value, changed to, changed by?
I am looking for Traits like centralized function to use in all models.
I am using Laravel 8 with PostgreSQL.
This answer is maybe outdated since it is Laravel 4. But if it works, it is quickest way to insert log in DB wherever save() method is called for that model.
https://stackoverflow.com/a/20694395/13893004

Issue with changing data type in Strapi collection type

I'm new to Strapi, and I have just created a couple of collections types, one of them has a field named description set to Long text.
I'd like to change the data type from Long text to Rich text, is there a way to edit the data type on this field, or do I need to delete and recreate it with the new data type?
you need to delete and re-create the data type. if you create it by giving the same name, then you will not lose data because your database will keep the field without deleting it.

Is there a way how to recreate a field for a Dynamics CRM entity?

Our particular situation is that we have a DateOnly field and would like to change it to DateTime field supporting also the time portion. The operation is not allowed in UI and it's also stated in the documentation. Hence, I excepted deleting the field and recreating it with the new setting would work.
However when I try to create the field with the same name the Duplicate Field Name error is thrown. I've read the column actually still exists behind in the DB.
Of course, I could create a field with a new name but it would require changing all related workflows and code customizations.
Is there a way how to overcome this issue?
Deleting and recreating an attribute with the same name but different type should work - of course with the caveat that you have to remove all dependencies before deleting the attribute and recreate them with the new attribute.
The Duplicate Field Name error seems to indicate that the field still exists - perhaps the entity needs to be published after deleting.
You may also find the XrmToolbox tool Attribute Manager helpful.
It allows you to migrate an attribute and its data to a new attribute.

The data reader is incompatible with the specified... A member of the type, 'Finalised', does not have a corresponding column in the data reader

I have added a column in my Sql Server Db then in VS i updated model from database, there a template auto generated some code.
The code compiled fine, but when i try access a the data base, the following error occurs:
The data reader is incompatible with the specified
'CompassModel.tbSalesContract'. A member of the type, 'Finalised',
does not have a corresponding column in the data reader with the same
name.
Finalised is the new column i added to my database.
Does anyone know how to track this down, and if so, is there a fix or methodology to follow to avoid in the future?
If you are using a SP then update the newly added column in that Or If you are using inline query put the exact name of the newly added column . The template you are talking about does not contain the newly added column name ..Try to edit the template ..the issue will be resolved.
If you are using a SP, then please make sure the alias names used.. ie. for eg: It should be written as
fieldname as 'aliasname'
thanks,
criss thomas
Hopefully this helps someone out but when I received this error I was trying to return an entity type from a stored procedure.
To fix this I had to add the correct function import mapping. In your edmx go to the Model Browser view and navigate to Funtion Imports. Right click your sproc name and select function import mapping. There you can map your sproc return results to the appropriate entity property.

LINQ-to-Entities, Ambiguous Column Name with association between two views with the same column name

I am just getting into Entity Framework for the first time beyond simple examples.
I am using the model-first approach and am querying the data source with LINQ-to-Entities.
I have created an entity model that I am exposing as an OData service against a database where I do not control the schema. In my model, I have two entities that are based off of two views in this database. I've created an association between the two entities. Both views have a column with the same name.
I am getting the error:
Ambiguous column name 'columnname'. Could not use view or function 'viewname' because of binding errors.
If I was writing the SQL statement myself, I'd qualify one of the column names with an alias to prevent this issue. EF apparently isn't doing that. How do I fix this, short of changing the view? (which I cannot do) I think this does have something to do with these entities being mapped to views, instead of being mapped to actual tables.
Assuming you can change the model have you tried going into the model and just changing one of the column names? I can still see how it might be problematic if the two views are pulling back the same column from the same table. I can tell that when working directly with a model mapped to tables, having identically named columns is not a problem. Even having multiple associations to the same table is handled correctly, the Navigation Properties are automatically given unique names. Depending on which version of EF you used you should be able to dig into the cs file either under the model or under the t4 template file and see what's going on. Then you can always create a partial class to bend it to your will.

Resources